hello i have this part of my code:
static void Main(string[] args)
{
Console.WriteLine("Memory mapped file reader started");
using (var file = MemoryMappedFile.OpenExisting("sensor"))
{
using (var reader = file.CreateViewAccessor(0, 3800))
{
var bytes = new byte[4051];
Console.WriteLine("Reading bytes");
for (var i = 0; i < bytes.Length; i++)
Console.Write((char)bytes[i] + "");
Console.WriteLine(string.Empty);
}
}
Console.WriteLine("Press any key to exit ...");
Console.ReadLine();
}
which opens the shared memory and then writes it to var bytes and displays it. how would i instead write it to a string? i know it has something to do with “var bytes = new byte[4051];” but i cant write “byte” to a new string obviously.
PS the output of the code now(with the array) is simple text: ABCDEFG… etc
thanks
If it’s textual information you’re trying to write, just pick encoding, and use
GetStringon the data.If it’s binary data you want to display textually (as in hex), then you’ll need an extension method or otherwise to convert it.