public class EmbeddedClientStream {
public const int MaxMessageLength = 100;
public void SendMessage(string message) {
// TODO truncate to 100 bytes max after encoding and send message
Console.WriteLine($"Sent message: \"{message}\" ({Encoding.UTF8.GetBytes(message).Length} bytes UTF8)");
}
public void SendMessage(EmbeddedClientStreamInterpolatedStringHandler interpolatedStringHandler) {
SendMessage(interpolatedStringHandler.GetFormattedText());
}
}
Code snippet taken from "Complete C# Quick Reference - C# 10".