[英]Error when converting VB.Net to C#
I have this VB.Net function ( from other project ) which I need to convert into C#
. 我有这个VB.Net函数( 来自其他项目 ),我需要将其转换为
C#
。
Private Function Convert(ByVal Value As String) As String
Dim transformed = Encoding.Unicode.GetBytes(Value).Select( _
Function(item) Not item)
Return Encoding.Unicode.GetString(transformed.ToArray())
End Function
Here's what I've tried: 这是我尝试过的:
private string Convert(string Value)
{
return Encoding.Unicode.GetString(Enumerable.ToArray<byte>(Enumerable.Select<byte, byte>((IEnumerable<byte>)Encoding.Unicode.GetBytes(Value),
(Func<byte, byte>)(item => ~item))));
}
I am getting two errors: 我遇到两个错误:
Can anyone help me on this? 谁可以帮我这个事?
You can try this C# code. 您可以尝试此C#代码。
private string Convert(string Value)
{
dynamic transformed = Encoding.Unicode.GetBytes(Value).Select(item => (byte)~item);
return Encoding.Unicode.GetString(transformed.ToArray());
}
I have used this tool to convert - http://converter.telerik.com/ 我已使用此工具进行转换-http: //converter.telerik.com/
Try the below code. 试试下面的代码。
I am not sure why LINQ Select converts the byte array to an int array, hence the explicit cast. 我不确定LINQ Select为什么将字节数组转换为int数组,从而进行显式转换。
private string Convert(string value)
{
var invertedBytes = Encoding.Unicode.GetBytes(value).Select(b => (byte)~b).ToArray();
return Encoding.Unicode.GetString(invertedBytes);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.