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

C# List Insert用法
C# code
string[] tableArray = query.tablestr.Split(',');
            Dictionary<string, int> Lengths = new Dictionary<string, int>();
            for (int n = 0; n < tableArray.Length - 1; n++)
            {
                for (int u = 0; u < TableLengths.Count; u++)
                {
                    if (TableLengths[u].Name == tableArray[n])
                    {
                        Lengths.Add(TableLengths[u].Name, TableLengths[u].Length);
                    }
                }
            }
            var list = (from d in Lengths orderby d.Value ascending select d).ToList();//排序
//我现在要对list进行插入操作
//请问怎么在list中插入<string, int>这种类型的元素啊



------解决方案--------------------
C# code

            Dictionary<string, int> Lengths = new Dictionary<string, int>();
            Lengths.Add("a", 1);
            Lengths.Add("b", 2);
            Lengths.Add("c", 3);
            var list = (from d in Lengths orderby d.Value ascending select d).ToList();
            list.Add(new KeyValuePair<string, int>("d", 4));

------解决方案--------------------
探讨
C# code
string[] tableArray = query.tablestr.Split(',');
Dictionary<string, int> Lengths = new Dictionary<string, int>();
for (int n = 0; n < tableArray.Length - 1; n++)
……