0

What is the point of declaring variables with '?' mark?

class SomeType
{
}

SomeType a = null;
SomeType? b = null;

Is there any difference between variables a and b?

mwal
  • 151
  • 3
  • 10
  • 3
    Yes: the compiler will warn you that the first one is assigning a null value to a variable that's intended to not be null. I suggest you read https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/nullable-reference-types - it's a very big topic. – Jon Skeet Aug 10 '20 at 08:14
  • Please refer this article https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/nullable-value-types – Sowmyadhar Gourishetty Aug 10 '20 at 08:15
  • To upvoters: duplicate questions (which already have answer elsewhere) typically shows lack of research ([here](https://www.google.com/search?q=What+is+the+point+of+declaring+variables+with+%27?%27+mark?+site:stackoverflow.com) are results of search by exact question title) and should not be upvoted. Consider to upvote duplicate instead. – Sinatr Aug 10 '20 at 08:30
  • I am not asking what 'int?' means. I am asking what is the difference between a and b? – mwal Aug 10 '20 at 13:22

0 Answers0