zoukankan      html  css  js  c++  java
  • var

    var 隐式类型的本地变量是强类型变量(就好像您已经声明该类型一样),但由编译器确定类型。

    // Example #1: var is optional because
    // the select clause specifies a string
    string[] words = { "apple", "strawberry", "grape", "peach", "banana" };
    var wordQuery = from word in words
                    where word[0] == 'g'
                    select word;

    // Because each element in the sequence is a string,
    // not an anonymous type, var is optional here also.
    foreach (string s in wordQuery)
    {
        Console.WriteLine(s);
    }

    // Example #2: var is required because
    // the select clause specifies an anonymous type
    var custQuery = from cust in customers
                    where cust.City == "Phoenix"
                    select new { cust.Name, cust.Phone };

    // var must be used because each item
    // in the sequence is an anonymous type
    foreach (var item in custQuery)
    {
        Console.WriteLine("Name={0}, Phone={1}", item.Name, item.Phone);
    }

  • 相关阅读:
    [BJDCTF 2nd]fake google
    flask之ssti模板注入初窥
    ctfshow-web14
    ctfshow-web 13
    ctfshow-web12
    ctfshow-web 11
    ctfshow-web10
    ctfshow-web9
    python学习笔记(四)- 常用的字符串的方法
    python学习笔记(三)- 字典、集合
  • 原文地址:https://www.cnblogs.com/greencolor/p/1731331.html
Copyright © 2011-2022 走看看