日期:2014-05-18  浏览次数:21365 次

C# 关于字符串数组的赋值与使用,给ID001 - ID100 的string 数组(或者Dictionary)赋值?

关于字符串数组的赋值与使用,给ID001 - ID100 的string 数组(或者Dictionary)赋值,然后传到另一个函数,并且使用ID001- ID100的名称和值:

1. 定义一个object,包含ID和值(string)

ID001
ID002
...
ID100



2. 给ID赋值
ID001 = xxxx
ID002 = xxxx
...
ID100 = xxxx


3. 传送object到另一个函数

4. 循环读取ID001值

fields["ID001"] = xxxx;
。。。


------解决方案--------------------
Dictionary<string,string> dic=new Dictionary<string,string>();
dic.Add("ID001","xxxx");
.....

void Fun(Dictionary<string,string> dic)
{
dic.ToList().ForEach(x=>{Console.Write("Key={0},Value={1}",x.Key,x.Value);});
}
------解决方案--------------------
C# code
        Dictionary<string, string> dictionary = new Dictionary<string, string>(100);
        for (int i = 1; i <= 100; i++)
            dictionary.Add("ID" + i.ToString("D3"), i.ToString());