根据我存储值的要求,选择最佳方法是什么

时间:2011-09-06 13:23:29

标签: c# asp.net .net-2.0

我有一个带有一些数据和复选框的网格视图。假设我的数据如下:

  check box    EmpID      PayID
                123         1
               1234         1
               1234         2

我想根据PayID存在相应的EmpID值。如果我从可用的复选框中选择这两个,我想检查哪个payid属于哪个EmpID可以让任何人给我一个实现此目的的想法。

1 个答案:

答案 0 :(得分:0)

以下是根据您的要求实现更改的方式

namespace ConsoleApplication1
{
class Program
{
    static void Main(string[] args)
    {
        int[] EmpIds = new int[] { 123, 1234, 1234 };
        int[] PayIds = new int[] { 1, 1, 2 };
        Dictionary<int, List<int>> dict = new Dictionary<int, List<int>>();

        // populate dictionary
        for (int i = 0; i < EmpIds.Length; i++)
        {
            if (!dict.ContainsKey(EmpIds[i]))
            {
                List<int> values = new List<int>();
                dict.Add(EmpIds[i], values);
            }
            dict[EmpIds[i]].Add(PayIds[i]);
        }
        foreach (int k in dict.Keys)
        {
            foreach (int v in dict[k]) Console.WriteLine("{0} -> {1}", k, v);
            Console.WriteLine();
        }
        Console.ReadKey();
    }
}
}
相关问题