简体   繁体   中英

Concat byte values with a operator?

In PHP I can concat every value with each other with ' . ' operator.
Now I want to concat some byte values in c# like this:

$byteData = "\x00\x00" . "Soroush" . "\x20";

Is it posible in c#?

尝试这个:

    byte[] byteData = (new byte[]{0,0}).Concat(Encoding.UTF8.GetBytes("asas")).Concat(new byte[]{20}).ToArray();

You can use operator + :

string string_variable = "great";
string test = "This is a " + string_variable + " test";

You can convert byte array to string:

string value = ASCIIEncoding.ASCII.GetString(byteArray)

Or, for UTF-8 use

string System.Text.Encoding.UTF8.GetString(byte[])

To convert a string back to a byte array:

byte[] byteArray = Hex.decodeHex(str.toCharArray());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM