Converting a string to a byte array in C#: how to do it correctly?
Hello everyone. I'm a beginner C# developer and I've encountered a problem when working with network requests and files. I need to convert a regular string into a byte array (byte[]) to send it through a socket or write it to a binary file.
The problem is that I don't understand which method is correct. I tried using `BitConverter.GetBytes()`, but it returns an array where each character takes 4 bytes, which is clearly not what I expected. I've also seen mentions online of `Encoding.ASCII.GetBytes()` and `Encoding.UTF8.GetBytes()`. What's the difference? If I just write `(byte[])myString` — it doesn't compile at all.
Here's an example of my code that doesn't work the way I want:
```csharp
string message = "Привет, мир!";
byte[] bytes = BitConverter.GetBytes(message); // Error or not