Linq查询Dictionary

    技术2022-05-19  20

    System.Collections.Generic.Dictionary<int, int> arr = new System.Collections.Generic.Dictionary<int, int>(); arr.Add(0, 5); arr.Add(1, 1); arr.Add(2, 9); arr.Add(3, 3); arr.Add(4, 4); arr.Add(5, 0); arr.Add(6, 8); var m = from item in arr         select item; foreach (var item in m) {     Response.Write(item .Value .ToString() + "<br>"); }

    我们可以发现在查询 Dictionary 时,查询语句是一样的,但输出时,不再是 item.ToString(),而是 item.Value.ToString(),并且我们在写完“item.”后,“Value”会自动出现 IntelliSense 中,不需要我们记忆。


    最新回复(0)