Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do C# Nullable variables still function as value types?

Tags:

c#

nullable

If I declare a nullable (either via Nullable or the ? symbol) variable from a value type, does it still respect the rules of value types (i.e. pass by value by default, deallocated when it falls out of scope, not when the garbage collector runs) or does it turn into a reference type since it's actually of type Nullable?

like image 596
RyanG Avatar asked Aug 09 '26 06:08

RyanG


1 Answers

The documentation is here:

http://msdn.microsoft.com/en-us/library/b3h38hb0.aspx

As you can see, the documentation describes this as the "nullable structure", indicating that it is a value type. Also, the documentation gives the first lines of the declaration of the type:

public struct Nullable<T> where T : struct, new()

again showing that the type is a value type.

like image 108
Eric Lippert Avatar answered Aug 11 '26 19:08

Eric Lippert