【发布时间】:2018-01-19 21:17:25
【问题描述】:
我正在尝试转换此代码
public static byte[] NewLine(this byte[] bytes, int feeds = 1)
{
return bytes.AddBytes(((IEnumerable<byte>) new byte[feeds]).Select<byte, byte>((Func<byte, byte>) (x => (byte) 10)).ToArray<byte>());
}
在线转换器生产这个
<System.Runtime.CompilerServices.Extension> _
Public Function NewLine(ByVal bytes() As Byte, Optional ByVal feeds As Integer = 1) As Byte()
Return bytes.AddBytes((DirectCast(New Byte(feeds - 1){}, IEnumerable(Of Byte))).Select(Of Byte, Byte)CType(Function(x) CByte(10), Func(Of Byte, Byte)).ToArray())
End Function
报错
重载解析失败,因为没有可访问的“选择”接受这个 类型参数的数量。
我该如何解决这个问题?
【问题讨论】:
-
你有 System.Linq 的导入吗?
-
是的,这就是为什么它说
no select accepts ... -
这是将
10添加到集合的一种非常复杂的方式。请注意,feeds的值被忽略,并且一直添加 10。我没有看到CType这个转换器 converter.telerik.com -
我用那个转换器
<System.Runtime.CompilerServices.Extension()> _ Public Function NewLine2(ByVal bytes As Byte(), Optional ByVal feeds As Integer = 1) As Byte() Return bytes.AddBytes(DirectCast(New Byte(feeds - 1) {}, IEnumerable(Of Byte)).[Select](Of Byte, Byte)(DirectCast(Function(x) CByte(10), Func(Of Byte, Byte))).ToArray(Of Byte)()) End Function得到了这个,它仍然有DirectCast,它仍然给出了上面的错误
标签: c# vb.net type-conversion