将VBNet LiNQ转换为C#

本文关键字:转换 LiNQ VBNet | 更新日期: 2023-09-27 18:22:14

如何将其转换为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/

将VBNet LiNQ转换为C#

我相信这是等价的:

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

完全相同,只是略有不同。

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

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

using System.Linq;

然后使用

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