用程序的属性可能没办法,我不清楚。你可以用比如xml文件的属性来弄。
解决方案 »
- 超出当前范围。 (异常来自 HRESULT:0x8002000A (DISP_E_OVERFLOW))
- WebBrowser控件的问题!
- 一个简单的关于datatable的问题
- 如何用Midi(c#)来模拟萨克斯的音效?
- 头大问题,繁体Win2K,繁体sql,简体输入,简体客户端浏览(IE),怎么样处理不出使乱码?
- 改变button 的image
- 事件问题???
- Microsoft Office PivotTable组件使用
- 请问取得文件的时间的函数怎么写。最好有源代码。
- 有谁能给我讲讲C#中的访问属性吗?看得真是头都大了。
- 求助c#实现屏幕录像(desktop record OR Screen record)
- 请教做winform程序时候的架构设计
using System;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApplication1 {
class ObjectWithProperties {
Dictionary<string, object> properties = new Dictionary<string,object>();
public object this[string name] {
get {
if (properties.ContainsKey(name)){
return properties[name];
}
return null;
}
set {
properties[name] = value;
}
}
}
class Comparer<T> : IComparer<ObjectWithProperties> where T : IComparable {
string m_attributeName;
public Comparer(string attributeName){
m_attributeName = attributeName;
}
public int Compare(ObjectWithProperties x, ObjectWithProperties y) {
return ((T)x[m_attributeName]).CompareTo((T)y[m_attributeName]);
}
}
class Program {
static void Main(string[] args) {
// create some objects and fill a list
var obj1 = new ObjectWithProperties();
obj1["test"] = 100;
var obj2 = new ObjectWithProperties();
obj2["test"] = 200;
var obj3 = new ObjectWithProperties();
obj3["test"] = 150;
var objects = new List<ObjectWithProperties>(new ObjectWithProperties[]{ obj1, obj2, obj3 });
// filtering:
Console.WriteLine("Filtering:");
var filtered = from obj in objects
where (int)obj["test"] >= 150
select obj;
foreach (var obj in filtered){
Console.WriteLine(obj["test"]);
}
// sorting:
Console.WriteLine("Sorting:");
Comparer<int> c = new Comparer<int>("test");
objects.Sort(c);
foreach (var obj in objects) {
Console.WriteLine(obj["test"]);
}
}
}
}
public class student
{
private string name;
private string number; public string Name
{
get{return name;}
set{name=value;}
}
public string Number
{
get{return number;}
set{nnumber=value;}
}
public Dictionary<string,object> DynamicProps{get;set;} public student(){ DynamicProps = new Dictionary<string,object>();}
}