C# to VB.NET Conversion : 'Take (of T)' Error

痞子三分冷 提交于 2019-12-25 14:21:49

问题


C# code

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

VB.NET Converted Code (i tried multiable ones. same result)

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

got an error on : (of Byte)

Error

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:


I don't have much experience with this, but it looks like if the VB compiler is able to infer the type arguments, it doesn't let you specify them explicitly. Assuming bytes is a Byte array (or an IEnumerable(Of Byte)), you should be able to use:

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

Frankly it's a little odd to redundantly specify the type arguments in C#, too - I'd normally write:

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


来源:https://stackoverflow.com/questions/31227873/c-sharp-to-vb-net-conversion-take-of-t-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!