All articles(网络文学目录) All Pictures(图片目录) All Softwares(软件目录)

 
C#3.0,新特性之隐式类型化数组_.net资料_编程技术

Writer: aaa Article type: Programming skills(编程技巧) Time: 2013/12/18 7:57:43 Browse times: 299 Comment times: 0

C#3.0,新特性之隐式类型化数组_.net资料_编程技术


Head photo

Go homepage
Upload pictures
Write articles

C#3.0 新特性之隐式类型化数组_.net资料_编程技术-你的首页-uuhomepage.com

  C#3.0这个特性是对隐式类型化本地变量的扩展,有了这个特性,将使我们创建数组的工作变得简单。我们可以直接使用"new[]"关键字来声明数组,后面跟上数组的初始值列表。在这里,我们并没有直接指定数组的类型,数组的类型是由初始化列表推断出来的。

   class AnonymousTypeArray : AppRunner.AbstractApplication
   {
   public override void Run()
   {
   var intArray = new[] { 1, 2, 3, 4, 5 };
   var doubleArray = new[] { 3.14, 1.414 };
   var anonymousTypeArray = new[] {
   new { Name="van’s", Sex=false, Arg=22 },
   new { Name="martin", Sex=true, Arg=23 }
   };
  
   Console.WriteLine(intArray);
   Console.WriteLine(doubleArray);
   Console.WriteLine(anonymousTypeArray[0].Name);
   }
   }

  上面的代码中,anonymousTypeArray变量的声明同时运用了隐式类型化数组和匿名类型两种特性,首先创建匿名类型,然后再初始值列表,推断出数组的确切类型。






There are 0 records,
Comment:
Must be registered users to comment(必须是注册用户才能发表评论)

Disclaimer Privacy Policy About us Site Map
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.