下面这种情况,用什么方法可以实现最快速的查找?有很多下面这样的结构的数据
Class S
{
string a;
string b;
int c;
int d;
}想按 a,b的值,从一组S的对象中快速查找。
用什么方法最快呢?我想到把S的对象根据a 和 b的值作为键值存储到哈希表中,
然后查找。
Class S
{
string a;
string b;
int c;
int d;
}想按 a,b的值,从一组S的对象中快速查找。
用什么方法最快呢?我想到把S的对象根据a 和 b的值作为键值存储到哈希表中,
然后查找。
Hashtable ht = new Hashtable();
ht.Add(S.a + "__" + S.b, S);
如果根据a,b作为键值放到Hash表中,时间复杂度就是O(1),但是a,b怎样才能做为一个hash表的键值呢?
这种方法我也考虑过了,但是S.a + "__" + S.b作为键值,会不会有错误的可能呢?
结构是这样的:
Class S
{
string a;
string b;
int c;
int d;
bool e;
}根据a,b,e的值查!
private void button1_Click(object sender, EventArgs e)
{
S[] ss = { new S("1", "1", 1, 1, true), new S("2", "2", 2, 2, true), new S("3", "3", 3, 3, true) };
IEnumerable<S> se = from s in ss where s.a == "1" && s.b == "1" select s;
MessageBox.Show(se.First().a);
}public class S
{
public string a;
public string b;
public int c;
public int d;
public bool e;
public S(string _a,string _b,int _c,int _d,bool _e)
{
a = _a;
b = _b;
c = _c;
d = _d;
e = _e;
}
}
或者存成DataTable,需要那个就实例化一个?