成都网站建设设计

将想法与焦点和您一起共享

字典---ToLookup-创新互联

------------------------------------------------------------------------------Person.cs

专注于为中小企业提供成都做网站、网站设计服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业碧江免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了数千家企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
    public class Person
    {
        public string Country { get; private set; }
        public string Name { get; private set; }
        public int Age { get; private set; }
        public Person(string country, string name, int age)
        {
            this.Country = country;
            this.Name = name;
            this.Age = age;
        }
    }
}

------------------------------------------------------------------------------主程序

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
    class Program
    {

        static void Main(string[] args)
        {
            //可以用于实现了IEnumerable的所有类
            //一个键关联多个值
            List lp = new List();
            lp.Add(new Person("中国", "张飞", 40));
            lp.Add(new Person("中国", "关羽", 43));
            lp.Add(new Person("中国", "刘备", 45));
            lp.Add(new Person("中国", "诸葛亮", 24));
            lp.Add(new Person("美国", "豪威尔", 40));
            lp.Add(new Person("美国", "奥巴马", 40));
            lp.Add(new Person("朝鲜", "金三胖", 40));
            lp.Add(new Person("印度", "印度阿三", 40));

            //传入一个Person对象,返回string
            var t = lp.ToLookup(r => r.Country);//键为Country(国家)
            foreach (Person item in t["中国"])//找到所有为中国的Person对象
            {
                Console.WriteLine(item.Name);
            }
            Console.ReadKey();
        }

    }
}

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


当前名称:字典---ToLookup-创新互联
当前路径:http://chengdu.cdxwcx.cn/article/dijhpi.html