探索!全新一代 Visual Studio 11[持续更新]
今天微软发布了Visual Studio 2011 Developer Preview,由于糟糕的线路,暂时还在下载中。
计划下载之后第一时间向大家汇报 VS 11 的体验感受。
已经下载完成,稍后安装。不过大家注意,只有Windows 7、Windows Server 2008 R2和Windows (Server) Developer Preview支持VS11,如果你还在使用Windows XP、Windows Server 2003和Windows Vista,那么很遗憾,在你打算升级操作系统之前就不用下载VS 11了。
先给出一些新特性,这些足够激动人心!
先看Visual Basic
Visual Basic 缺少一个 C# 2005 开始增加的特性,就是迭代器。
在C#中,我们可以使用yield return来实现迭代器,比如:
IEnumerable<string> split(string, source, char c){ string s = ""; for (int i = 0; i < source.Length; i++) { if (source[i] == c) { yield return s; s = ""; } else { s += new string(new char[] { source[i] }); } } if (s != "") yield return s;}
foreach (string s in split("hello world csharp", ' ')){ Console.WriteLine(s);}
Sub Main() For Each number As Integer In SomeNumbers() Console.Write(number & " ") Next ' Output: 3 5 8 Console.ReadKey()End SubPrivate Iterator Function SomeNumbers() As System.Collections.IEnumerable ' Use multiple yield statements. Yield 3 Yield 5 Yield 8End Function
// Synchronous version of a method that downloads the resource that a URI// links to and accesses its content.private byte[] GetByteArray(Uri currentURI){ // Declare an HttpClient object and increase the buffer size. HttpClient client = new HttpClient() { MaxResponseContentBufferSize = 1000000 }; // The Get method returns an HttpResponseMessage that contains the // content of the resource along with other information. HttpResponseMessage httpRM = client.Get(currentURI); // Use ReadAsByteArray to access the content as a byte array. return httpRM.Content.ReadAsByteArray();}// Asynchronous version of the same method.private async Task<byte[]> GetByteArrayAsync(Uri currentURI){ // Declare an HttpClient object and increase the buffer size. HttpClient client = new HttpClient() { MaxResponseContentBufferSize = 1000000 }; // The GetAsync method returns a Task(Of T), where T is an HttpResponseMessage. HttpResponseMessage httpRM = await client.GetAsync(currentURI); // Use ReadAsByteArray to access the content as a byte array. return httpRM.Content.ReadAsByteArray();}
[<Generate>]type Northwind = ODataService<"http://services.odata.org/Northwind/Northwind.svc">let db = new Northwind.NorthwindEntities()// A query expression.let query1 = query { for customer in db.Customers do select customer }query1|> Seq.iter (fun customer -> printfn "Company: %s Contact: %s" customer.CompanyName customer.ContactName)