zoukankan      html  css  js  c++  java
  • LINQ -- 匿名类型

    匿名类型注意事项:

    匿名类型只能和局部变量配合使用,不能用于成员。

    由于匿名类型没有名字,我们必须使用var关键字作为变量类型。

    不能设置匿名类型对象的属性。编译器为匿名类型穿件的属性是只读的。

    除了对象初始化语句的赋值形式,匿名类型的对象初始化语句还有两种允许的形式:简单标识符和成员访问表达式。这两种形式叫做投影初始化语句。例如下面的例子

    namespace ConsoleApplication44
    {
        class Other
        {
            static public string Name = "Mary Jones";
        }
        class Program
        {

            static void Main(string[] args)
            {
                string Mojor = "History";
                var student = new { Age = 19, Other.Name, Mojor }; //Age是赋值形式   Other.Name 是成员访问    Mojor 是标识符

                Console.WriteLine("{0}, Age  {1}, Mojor: {2}",student .Name ,student .Age , student .Mojor );
            }
        }
    }

  • 相关阅读:
    Leetcode Substring with Concatenation of All Words
    Leetcode Divide Two Integers
    Leetcode Edit Distance
    Leetcode Longest Palindromic Substring
    Leetcode Longest Substring Without Repeating Characters
    Leetcode 4Sum
    Leetcode 3Sum Closest
    Leetcode 3Sum
    Leetcode Candy
    Leetcode jump Game II
  • 原文地址:https://www.cnblogs.com/bedfly/p/11960466.html
Copyright © 2011-2022 走看看