现在需要使用一个名值对型的对象保存一组二维数组,但是对于System.Collection命名空间中的几个对象小弟全不熟悉。具体的要求是能够根据某一个具体的INT值,将对应的二维数组获取出来,而且希望尽量减少类型转换造成的性能损耗。也就是说,如果建议小弟存在Application或者Session中的话,那还是不浪费您打字的力气的,将获取出来的数据转换为二维数组就会损失不少性能,恐怕BOSS不会同意的。目前小弟想到的是构造一个Dictionary<int,string[,]>对象,不过又头疼如何遍历每个名值对,以及如何根据具体的int值获取到对应的数组。求高手指点。或者能给出更好的建议也行,因为小弟对HashTable什么的一点了解都没有。提前谢过了
ff.Add(1, new string[2] { "1", "2" });
ff.Add(2, new string[2] { "1", "2" });
string[] ss = ff[1];
还有看LZ的技术分不低哟,居然说没用过HashTable,真有点不相信,表忽悠我哟,偶是菜鸟,呵呵
ff.Add(1, new string[2] { "1", "2" });
ff.Add(2, new string[2] { "1", "2" });
string[] ss = ff[1];
Dictionary<int, string[]>.Enumerator enu = ff.GetEnumerator();
while (enu.MoveNext())
{
KeyValuePair<int, string[]> current = enu.Current;
int key = current.Key;
string[] value = current.Value;
}
偶也不是很熟悉,没有具体测试过,不过应该就是这样的用法,感觉这些函数都差不多,点了之后看着提示找函数用吧,呵呵
using System.Collections.Generic;class Program
{
static void Main(string[] args)
{
Dictionary<int, string[]> ff = new Dictionary<int, string[]>();
ff.Add(1, new string[2] { "1", "2" });
ff.Add(2, new string[2] { "3", "4" });
int find = 2;
foreach (KeyValuePair<int, string[]> f in ff)
{
if (f.Key == find)
{
foreach (string str in f.Value)
{
Console.WriteLine(str);
}
}
}
}
}