Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将LINQ C转换为VB.Net_C#_Vb.net_Linq - Fatal编程技术网

C# 将LINQ C转换为VB.Net

C# 将LINQ C转换为VB.Net,c#,vb.net,linq,C#,Vb.net,Linq,有人能把这个c linq代码转换成VB吗?我试过developerfusion,但没有成功 DataTable dt = dt1.Copy(); var result = dt .AsEnumerable() .Select(r => r.Field<string>(0)) .Select(s => string.Join("",

有人能把这个c linq代码转换成VB吗?我试过developerfusion,但没有成功

   DataTable dt = dt1.Copy();
        var result = dt
            .AsEnumerable()
            .Select(r => r.Field<string>(0))
            .Select(s => string.Join("",
                                 s.Select((x, i) => x == '0'
                                                    ? " "
                                                    : (i + 1).ToString()))
             ).ToList();
但它显示出错误

 Data type(s) of the type parameter(s) in extension method 'Public Function Select(Of S)(selector As System.Func(Of String, S)) As System.Data.EnumerableRowCollection(Of S)' defined in 'System.Data.EnumerableRowCollectionExtensions' cannot be inferred from these arguments. Specifying the data type(s) explicitly might correct this error.
我的datatable只有一列,看起来像 第一排1000000 第二排0010000 从第三行0100000等,我想得到的是用空格替换所有0,用位置号ie替换所有1;第一行的期望输出为1000000。第二行为0030000,第三行为0200000。就像这样

这里有一个工作示例:

出现错误的原因是文件顶部缺少Imports System.Linq


异常是显式地告诉您在Select中指定数据类型

作为数据表的Dim dt=新数据表 Dim结果=dt。 可计算的。 选择Functionr作为String0的DataRow r.Field。 选择函数作为字符串。连接 ,s.SelectFunctionx作为字符,i作为整数 返回Ifx=0c,i+1.t字符串 结束函数。 托利斯特
你说的“不起作用”是什么意思?这么多的反对票?你能解释一下错误吗?不过我觉得还不错!我用错误更新了我的问题,我得到的错误是获取错误“扩展方法中类型参数的数据类型”公共函数Selector作为System.FuncOf字符串,S作为System.Data.EnumerableRowCollectionOf S在“System.Data.EnumerableRowCollectionExtensions”中定义的不能从这些参数推断。显式指定数据类型可能会更正此错误。“@Cronaldo-您能发布数据表外观的小样本吗?或者最好还是在@Cronaldo创建一个示例——这是一个工作的dotnetfiddle示例-
 Data type(s) of the type parameter(s) in extension method 'Public Function Select(Of S)(selector As System.Func(Of String, S)) As System.Data.EnumerableRowCollection(Of S)' defined in 'System.Data.EnumerableRowCollectionExtensions' cannot be inferred from these arguments. Specifying the data type(s) explicitly might correct this error.
Dim dt as DataTable = new DataTable
dt.Columns.Add("col1")
dt.Rows.Add("1000000")
dt.Rows.Add("0010000")
dt.Rows.Add("0100000")      

Dim result = dt _
    .AsEnumerable() _
    .Select(Function(r) r.Field(Of String)(0)) _
    .Select(Function(s) string.Join("", s.Select(Function(x, i) _
        If(x = "0", "0", (i + 1).ToString())))).ToList()

For Each i As String in result
    Console.WriteLine(i)
Next