【问题标题】:C# to VB.NET Conversion : 'Take (of T)' ErrorC# 到 VB.NET 转换:“Take (of T)”错误
【发布时间】:2015-07-05 20:43:51
【问题描述】:

C#代码

byte[] array = bytes.Take<byte>(num).ToArray<byte>();

VB.NET 转换后的代码(我尝试了 multiable 的。相同的结果)

Dim array As Byte() = bytes.Take(Of Byte)(num).ToArray(Of Byte)()

出现错误:(of Byte)

错误

Extension method 'Public Function Take(count As Integer) As System.Collections.Generic.IEnumerable(Of TSource)' defined in 'System.Linq.Enumerable' is not generic (or has no free type parameters) and so cannot have type arguments

【问题讨论】:

    标签: c# vb.net byte


    【解决方案1】:

    我对此没有太多经验,但看起来如果 VB 编译器能够推断类型参数,它不会让您显式指定它们。假设bytesByte 数组(或IEnumerable(Of Byte)),您应该可以使用:

    Dim array As Byte() = bytes.Take(num).ToArray()
    

    坦率地说,在 C# 中冗余指定类型参数也有点奇怪 - 我通常会这样写:

    byte[] array = bytes.Take(num).ToArray();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-19
      • 1970-01-01
      • 2011-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多