0

I am new to C#, recently, I have noticed that Visual Studio generated the following line of code:

internal bool? variableName;

I tried to search on this forum and other sources on the meaning of the question mark, but couldn't seem to find anything. Could someone explain to me what does the ? represents.

darkvalance
  • 390
  • 4
  • 14
  • 3
    It indicates that `variableName` has a third state of `null` rather than just `true` and `false`. – Enigmativity Aug 17 '20 at 09:36
  • 3
    It's a [nullable value type](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/nullable-value-types) – Rup Aug 17 '20 at 09:36
  • 3
    `internal` means its can only be access from that project, `bool` is a boolean `?` means its nullable, `variableName` is well a variable name – TheGeneral Aug 17 '20 at 09:36
  • [Learn from the horse's mouth.](https://learn.microsoft.com/en-us/dotnet/csharp/tutorials/) – Zohar Peled Aug 17 '20 at 09:49

1 Answers1

1

It's called nullable value type. Refer official documentation here.

using System;

public class Test
{
    public static void Main()
    {
      bool? s = null;
      int? g = null;
    
        // bool ss = null; // => compilation error
        // int gg = null; // => compilation error
    }
}

It lets you assign "null" to a type in addition to it's allowed values.

internal is access modifier. From the official docs.

Internal types or members are accessible only within files in the same assembly

SRIDHARAN
  • 1,196
  • 1
  • 15
  • 35
  • 1
    It's not called a "null conditional operator". You've linked to the wrong documentation. Actually both links you've posted are wrong. – Enigmativity Aug 17 '20 at 09:42