从C#到VB.NET的转换:“ T取(T)”错误 [英] C# to VB.NET Conversion : 'Take (of T)' Error

查看:50
本文介绍了从C#到VB.NET的转换:“ T取(T)”错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C#代码

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

VB.NET转换后的代码(我尝试过多次转换。结果相同)

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

Dim array As Byte() = bytes.Take(Of Byte)(num).ToArray(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)),您应该可以使用:

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()

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

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();

这篇关于从C#到VB.NET的转换:“ T取(T)”错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆