2016年7月9日 星期六
[C#] Var 的使用與應用
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
// 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] == 'p'
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);
}
Console.ReadLine();
}
}
}
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言