public GetString ( byte bytes, int index, int count ) : string | ||
bytes | byte | |
index | int | |
count | int | |
return | string |
byte[] bytes = { 72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100 }; UnicodeEncoding unicode = new UnicodeEncoding(); string str = unicode.GetString(bytes); Console.WriteLine(str); //Output: Hello World
byte[] bytes = { 72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100 }; UnicodeEncoding unicode = new UnicodeEncoding(); string str = unicode.GetString(bytes); int byteCount = unicode.GetByteCount(str); Console.WriteLine(str); //Output: Hello World Console.WriteLine(byteCount); //Output: 22In both examples, we use the `UnicodeEncoding.GetString()` method to convert the byte array to a string. In example 2, we also use the `UnicodeEncoding.GetByteCount()` method to get the total number of bytes used to encode the string. The `System.Text` namespace containing the `UnicodeEncoding` class is a part of the .NET Framework.
public GetString ( byte bytes, int index, int count ) : string | ||
bytes | byte | |
index | int | |
count | int | |
return | string |