-7

I have VB code which I'm converting to C#. I've created a large chunk of the program but I'm stuck at one line of this fuction:

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

What I know is endByte is a Byte type array and I don't know what &HFE is and how to convert or typecast it in C#. Can anybody please help me?

5
  • There are some online converters - Google will help you ;-) Or you can use convert.net. Commented Apr 20, 2017 at 12:49
  • Just try to google: Online c# to vb.net Commented Apr 20, 2017 at 12:50
  • &HFE is a hex literal. In C# it translates to 0xFE Commented Apr 20, 2017 at 12:51
  • 1
    This and this tell you everything you need to know and can be found with simple Google searches. Commented Apr 20, 2017 at 12:55
  • @Waseem Tahir have you try my answer ? if it is help for u please accept it :) good luck Commented Apr 20, 2017 at 13:41

5 Answers 5

1

It's an array with a single value of hex FE. in C# you can write this as:

byte[] endByte = {0xFE};
Sign up to request clarification or add additional context in comments.

Comments

1

&HFE just means the hexadecimal for 254. In C# this would be:

byte[] endByte = { 0xFE };

1 Comment

Thanks, it was great help.
0

How about:

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");
    }
}

2 Comments

Thank, it was the exact thing I was searching for.
No problem. Feel free to vote up and accept and I'll love you forever :o)
0

Try some online converters, they are okay. Google will find many. ;)

Here an example from http://converter.telerik.com/

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");
    }
}

Comments

0

Try this.

you can compile the VB code and use the dissasembler in Reflector to see C# code. Some of the variable names will change.

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");
    }
}

in the internet have more online converters.here are some converters

http://converter.telerik.com/

http://www.carlosag.net/tools/codetranslator/

Sometimes the conversion is not 100% accurate, but it is definitely very helpful.you also can use Visual Studio 2012 plug-in named Language Convert (works perfectly with 2010/2012)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.