zoukankan      html  css  js  c++  java
  • C#3.0特性之列表对象的赋值更容易

                List<Customer> customers = new List<Customer>
                {
                  new Customer { Id = 1, Name="Dave", City="Sarasota" },
                  new Customer { Id = 2, Name="John", City="Tampa" },
                  new Customer { Id = 3, Name="Abe", City="Miami" }
                };

    而在2.0时代,我们为列表对象赋值要这样写:

                List<Customer> customers2 = new List<Customer>();
                customers2.Add(new Customer { Id = 1, Name = "Dave", City = "Sarasota" });
                customers2.Add(new Customer { Id = 2, Name = "John", City = "Tampa" });
                customers2.Add(new Customer { Id = 3, Name = "Abe", City = "Miami" });

    而在对象单个实体赋值时也就方便了,而且可读性也强了

    2.0时代:          

    Customer customer = new Customer();

                customer.Id = 1;
                customer.Name = "zzl";
                customer.City = "beijing";
     
     3.0时代     
               Customer customer2 = new Customer
                {
                    Id = 1,
                    Name = "zzl",
                    City = "beijing"
                };
  • 相关阅读:
    元组,字典
    python字符串
    tensorflow 学习笔记
    tensorflow example1
    python第二章(2)列表
    python3.5学习第二章(1)标准库,bytes
    类加载过程
    数据值与地址值
    类的初始化与实例化顺序
    SpringCloudBus
  • 原文地址:https://www.cnblogs.com/lori/p/2088308.html
Copyright © 2011-2022 走看看