C#到VB.NET转换:' Take(of T)'错误

时间:2015-07-05 06:53:33

标签: c# vb.net byte

C#代码

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

VB.NET转换代码(我试过多个。同样的结果)

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

1 个答案:

答案 0 :(得分:3)

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

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

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

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