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?

5
  • Read my answer here: stackoverflow.com/a/69433657/4800344 - does that help? Mar 9, 2022 at 13:51
  • 3
    Also this blog post and this one
    – canton7
    Mar 9, 2022 at 13:53
  • @canton Does it just help you write code more safely (escape NullReferenceException)?
    – Aarnihauta
    Mar 9, 2022 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 9, 2022 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 Mar 10, 2022 at 7:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.