1

In C#-8 we have seen nullable reference types. I noob in C# and I don't know why it's neccessary?

Ok, I have methods:

#nullable enable
public void Method1(string? arg) { }
#nullable disable
public void Method2(string arg) { }

What are the principial differences between Method1 and Method2?

Aarnihauta
  • 441
  • 3
  • 10
  • Read my answer here: https://stackoverflow.com/a/69433657/4800344 - does that help? – Ermiya Eskandary Mar 09 '22 at 13:51
  • 3
    Also [this blog post](https://devblogs.microsoft.com/dotnet/nullable-reference-types-in-csharp/) and [this one](https://devblogs.microsoft.com/dotnet/embracing-nullable-reference-types/) – canton7 Mar 09 '22 at 13:53
  • @canton Does it just help you write code more safely (escape NullReferenceException)? – Aarnihauta Mar 09 '22 at 13:57
  • 2
    Yes. But there's no "just" -- avoiding unexpected nulls is a huge benefit, particularly in larger codebases where it's harder to keep track of the edge cases where things can be null by yourself – canton7 Mar 09 '22 at 13:59
  • A frequently asked question here is "why is my code throwing this nullreference exception". So preventing that is quite a big deal – Hans Kesting Mar 10 '22 at 07:29

0 Answers0