question

AnatoliKoutsevol-0585 avatar image
0 Votes"
AnatoliKoutsevol-0585 asked ·

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

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

dotnet-csharpdotnet-runtime-framework
· 2
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

FWIW, using VS 2017 Community I see the following results when using the
indicated .NET versions:

4.6.1

"abc" (3), zero-terminated: False
"abc " (4), zero-terminated: True

4.7.2

"abc" (3), zero-terminated: False
"abc " (4), zero-terminated: True

  • Wayne

0 Votes 0 ·

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

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
...
</Project>

0 Votes 0 ·

1 Answer

WayneAKing-0228 avatar image
0 Votes"
WayneAKing-0228 answered ·

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

·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.