我想將以下LINQ代碼從C#轉換爲VB.NET。這裏是C#,接着我嘗試了VB。在VB中,我想聲明rowList爲IEnumerable(Of IGrouping(Of Char, String))
,但它返回IEnumerable(Of IEnumerable(Of Char, String))
。如何將LINQ從C#轉換爲VB.NET?
string rows = "ABC";
string cols = "123";
string[] squares = (from r in rows from c in cols select "" + r + c).ToArray();
IEnumerable<IGrouping<Char, String>> rowList = (from r in rows from s in squares where s.Contains(r) group s by r into g select g);
Dim rows As String = "ABC"
Dim cols As String = "123"
Dim squares As String() = (From r In rows From c In cols Select "" & r & c).ToArray()
Dim rowList = (From r In rows From s In squares Where s.StartsWith(r) Group By r Into g = Group Select g).Dump("rowList")
謝謝,這是有效的。 Linq語法不能被使用或僅僅是一個區別的錯誤嗎? – 2012-01-08 19:27:52
我不認爲它是一個錯誤,因爲在VB.NET和C#過程linq的方式的差異被承認。我認爲它涉及語言設計問題。 – Mzn 2012-01-08 19:41:02