.net 5.0 seems to be wrong in detecting zero-terminzted string

Anatoli Koutsevol 21 Reputation points
2020-12-09T17:09:31.873+00:00

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

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,362 questions
.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,130 questions
{count} votes

Accepted answer
  1. WayneAKing 4,921 Reputation points
    2020-12-09T22:12:08.637+00:00

    But that is not about FW 4.7.2, that is about .NET 5.0

    Yes, of course. That's obvious.

    The point of my reply is that the earlier versions of .NET give
    the expected results.

    So I suggest you use the "Send Feedback->Report a Problem"
    link form the VS Help menu to report your findings.

    • Wayne
    0 comments No comments

0 additional answers

Sort by: Most helpful