将VBNet LiNQ转换为C#

时间:2012-02-03 00:59:59

标签: c# linq

如何将其转换为C#代码?

Dim newArray() as String = From sRow In iDatatable.Rows.Cast(Of DataRow)() Where sRow("iType").ToString = "ST" Select CStr(sRow("iResult"))).ToArray()

我试过这个网站,但没有一个工作过。

http://www.developerfusion.com/tools/convert/csharp-to-vb/
http://www.carlosag.net/Tools/CodeTranslator/

3 个答案:

答案 0 :(得分:2)

我相信这会是公平的:

string[] newArray = iDatatable.Rows.Cast<DataRow>()
         .Where(sRow => sRow["iType"].ToString() == "ST")
         .Select(sRow => sRow["iResult"].ToString())
         .ToArray();

答案 1 :(得分:1)

完全相同,只有细微差别。

string[] newArray = (from sRow in iDatatable.Rows.Cast<DataRow>() where sRow["iType"].ToString() == "ST" select (string)sRow["iResult"]).ToArray();

答案 2 :(得分:1)

确保在命名空间之前有这个。

using System.Linq;

然后使用

string[] newArray = iDatatable.Rows.Cast<DataRow>()
                .Where(sRow => sRow["iType"].ToString() == "ST")
                .Select(sRow => sRow["iResult"].ToString())
                .ToArray();