c# Char, Delphi code translate - Need quick answer, easy points!

Hi,

I need to do the same as below (Delphi code) but in c#, I'm not sure about the #0 Char part:

...SendStr(#0 + Chr(Length(DataRec)) + DataRec);

Just this line above, how do I do this in c#, not the sending just the #0 part in the beginning?

Full code

If TCPClient.Socket.Connected Then
        Begin
          If Length(DataRec) > 256 Then
          Begin
              If Length(DataRec) > 512 Then
              Begin
                  TCPClient.Socket.SendStr(#2 + Chr(Length(DataRec) - 512) + DataRec);
                  Memo2.Lines.Add('DataOut: ' + #2 + Chr(Length(DataRec) - 512) + DataRec);
              End
              Else
              Begin
                  TCPClient.Socket.SendStr(#1 + Chr(Length(DataRec) - 256) + DataRec);
                  Memo2.Lines.Add('DataOut: ' + #1 + Chr(Length(DataRec) - 256) + DataRec);
              End;
          End
          Else
          Begin
              TCPClient.Socket.SendStr(#0 + Chr(Length(DataRec)) + DataRec);
              Memo2.Lines.Add('DataOut: ' + Chr(Length(DataRec)) + DataRec);
          End;
MokwajaAsked:
Who is Participating?
 
dkloeckCommented:
as the #0 you can just use a byte and convert it to the right char if needed
0
 
dkloeckCommented:
what does the #0 mean in delphi,
you are at the c# programming forum you know ;)
0
 
dkloeckCommented:
char is allways a 16 bit in c# but you could check if the char you get is part of the byte uyou want to use and send it as byte
0
 
sumixCommented:
For #0 you can do (char)0 (returns a char) or \u0000 (returns a string), but both are Unicode.

Chr(Length(DataRec))
          can be translated in c# like:
System.Text.Encoding.ASCII.GetString(new byte[]{(byte)DataRec.Length});
0
 
MokwajaAuthor Commented:
Cool thanks dkloeck and sumix!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.