如何将此VB代码转换为c#?
我有VB代码,我正在将其转换为C#。我已经创建了一大块程序,但我只停留在这一行:如何将此VB代码转换为c#?,c#,vb.net,sockets,C#,Vb.net,Sockets,我有VB代码,我正在将其转换为C#。我已经创建了一大块程序,但我只停留在这一行: Private Sub Arduino_Write(ByVal Output As String) If Not IsNothing(networkStream) Then Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(Output) Dim endByte As [Byte]() = {&HFE}
Private Sub Arduino_Write(ByVal Output As String)
If Not IsNothing(networkStream) Then
Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(Output)
Dim endByte As [Byte]() = {&HFE}
networkStream.Write(sendBytes, 0, sendBytes.Length)
networkStream.Write(endByte, 0, 1)
Else
MsgBox("ERROR")
End If
End Sub
我知道的是endByte是一个字节类型的数组,我不知道&HFE是什么,也不知道如何在C#中转换或类型转换它。
有人能帮我吗?怎么样:
private void Arduino_Write(string Output)
{
if (networkStream != null) {
var sendBytes = Encoding.ASCII.GetBytes(Output);
var endByte = { 0xfe };
networkStream.Write(sendBytes, 0, sendBytes.Length);
networkStream.Write(endByte, 0, 1);
} else {
Interaction.MsgBox("ERROR");
}
}
&HFE
仅表示254的十六进制。在C#中,这将是:
byte[] endByte = { 0xFE };
尝试一些在线转换器,他们是好的。谷歌会发现很多 这里有一个例子
它是一个数组,只有一个十六进制FE值。在C中,你可以这样写:
byte[] endByte = {0xFE};
试试这个
您可以编译VB代码,并在中使用disassembler查看C代码。某些变量名将更改
private void Arduino_Write(string Output)
{
if ((networkStream != null)) {
Byte[] sendBytes = Encoding.ASCII.GetBytes(Output);
Byte[] endByte = { 0xfe };
networkStream.Write(sendBytes, 0, sendBytes.Length);
networkStream.Write(endByte, 0, 1);
} else {
Interaction.MsgBox("ERROR");
}
}
在互联网上有更多的在线转换器
有时,转换不是100%准确的,但肯定非常有用。您也可以使用Visual Studio 2012插件命名(与2010/2012完美配合)有一些在线转换器-谷歌会帮助您;-)或者你可以使用convert.net。只要试着谷歌:在线c#to vb.net
&HFE
是一个十六进制文字。在C#中,它被翻译成0xFE
,告诉你需要知道的一切,并且可以通过简单的谷歌搜索找到。@Waseem Tahir你试过我的答案吗?如果这对你有帮助,请接受:)祝你好运,这帮了大忙。谢谢,这正是我要找的东西。没问题。请随意投票并接受,我将永远爱你:o)
private void Arduino_Write(string Output)
{
if ((networkStream != null)) {
Byte[] sendBytes = Encoding.ASCII.GetBytes(Output);
Byte[] endByte = { 0xfe };
networkStream.Write(sendBytes, 0, sendBytes.Length);
networkStream.Write(endByte, 0, 1);
} else {
Interaction.MsgBox("ERROR");
}
}