C# 到 VB.NET 转换:'Take (of T)' 错误
C# to VB.NET Conversion : 'Take (of T)' Error
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
我对此经验不多,但看起来如果 VB 编译器能够推断类型参数,它不会让您明确指定它们。假设 bytes
是一个 Byte
数组(或 IEnumerable(Of Byte)
),你应该可以使用:
Dim array As Byte() = bytes.Take(num).ToArray()
坦率地说,在 C# 中冗余指定类型参数也有点奇怪 - 我通常会写:
byte[] array = bytes.Take(num).ToArray();
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
我对此经验不多,但看起来如果 VB 编译器能够推断类型参数,它不会让您明确指定它们。假设 bytes
是一个 Byte
数组(或 IEnumerable(Of Byte)
),你应该可以使用:
Dim array As Byte() = bytes.Take(num).ToArray()
坦率地说,在 C# 中冗余指定类型参数也有点奇怪 - 我通常会写:
byte[] array = bytes.Take(num).ToArray();