How to convert a UTF-8 byte array (byte[]) to a string in C#?
Hello everyone! I'm new to C# and encountered a problem when working with network data. I have a method that receives a byte array (byte[]) from a TCP socket. I know these bytes are encoded in UTF-8, and I need to convert them to a regular string to output to the console or process further.
Here's an example of the code I have:
```csharp
byte[] data = new byte[] { 72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100 }; // "Hello World" in UTF-8
string result = data.ToString(); // I get "System.Byte[]"
Console.WriteLine(result);
```
Obviously, `data.ToString()` doesn't work — it returns the type name, not the content. I tried using `Convert.ToBase64String()`, but that gives a base64 string, not a readable form. I also tried simply casting to a string using (