读书人

C# List Insert用法解决思路

发布时间: 2012-05-09 12:13:59 作者: rapoo

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++)
……

读书人网 >C#

热点推荐