The following code:
class Program
{
static void Main(string[] args)
{
const string s = "abc";
const string sz = "abc\0";
void Report(string str)
=> Console.WriteLine($"\"{str}\" ({str.Length}), zero-terminated: {str.EndsWith("\0")}");
Report(s);
Report(sz);
}
}
gives the following output for target framework .net 5.0:
"abc" (3), zero-terminated: True
"abc" (4), zero-terminated: True
For target framework .netcoreapp3.1 the code outputs the following lines:
"abc" (3), zero-terminated: False
"abc" (4), zero-terminated: True
As for me, .net core 3.1 behavior looks correct and .net 5.0 does not.
I am wondering what is the reason for such radical code behavior modification in .net 5.0?
Thanks,
Anatoli