<p>In C# are the nullable primitive types (i.e. <code>bool?</code>) just aliases for their corresponding <code>Nullable&lt;T&gt;</code> type or is there a difference between the two?</p>

[{'answer_id': 56520, 'author': 'Curt Hagenlocher', 'author_id': 533, 'author_profile': 'https://Stackoverflow.com/users/533', 'pm_score': 3, 'selected': False, 'text': '<p>A <code>Nullable&lt;T&gt;</code> is a structure consisting of a T and a bit flag indicating whether or not the T is valid.  A <code>Nullable&lt;bool&gt;</code> has three possible values: true, false and null.</p>\n\n<p><strong>Edit:</strong> Ah, I missed the fact that the question mark after "bool" was actually part of the type name and not an indicator that you were asking a question :).  The answer to your question, then, is "yes, the C# <code>bool?</code> is just an alias for <code>Nullable&lt;bool&gt;</code>".</p>\n'}, {'answer_id': 56522, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>Null primitives are just regular primitives wrapped in Nullable.  Any appearances to the contrary are just the compiler and syntactical sugar.</p>\n'}, {'answer_id': 56523, 'author': 'spoulson', 'author_id': 3347, 'author_profile': 'https://Stackoverflow.com/users/3347', 'pm_score': 2, 'selected': False, 'text': "<p>A <code>bool</code> is a value type, therefore it can't contain a NULL value.  If you wrap any value type with <code>Nullable&lt;&gt;</code>, it will give it that ability.  Moreover, access methods to the value change by additional properties <code>HasValue</code> and <code>Value</code>.</p>\n\n<p>But to the question: <code>Nullable&lt;bool&gt;</code> and <code>bool?</code> are aliases.</p>\n"}, {'answer_id': 56525, 'author': 'samjudson', 'author_id': 1908, 'author_profile': 'https://Stackoverflow.com/users/1908', 'pm_score': 5, 'selected': False, 'text': '<p>There is no difference between <code>bool? b = null</code> and <code>Nullable&lt;bool&gt; b = null</code>. The <code>?</code> is just C# compiler syntax sugar.</p>\n'}, {'answer_id': 56526, 'author': 'Mark Ingram', 'author_id': 986, 'author_profile': 'https://Stackoverflow.com/users/986', 'pm_score': 4, 'selected': False, 'text': "<p>To access the value of the bool? you need to do the following:</p>\n\n<pre><code>bool? myValue = true;\nbool hasValue = false;\n\nif (myValue.HasValue &amp;&amp; myValue.Value)\n{\n  hasValue = true;\n}\n</code></pre>\n\n<p>Note you can't just do:</p>\n\n<pre><code>if (myValue)\n{\n  hasValue = true;\n}\n</code></pre>\n"}, {'answer_id': 56539, 'author': 'Steve Morgan', 'author_id': 5806, 'author_profile': 'https://Stackoverflow.com/users/5806', 'pm_score': 7, 'selected': True, 'text': '<p>If you look at the IL using <a href="http://msdn.microsoft.com/en-us/library/f7dy01k1%28v=vs.100%29.aspx" rel="noreferrer">Ildasm</a>, you\'ll find that they both compile down to <code>Nullable&lt;bool&gt;</code>.</p>\n'}, {'answer_id': 56540, 'author': 'morechilli', 'author_id': 5427, 'author_profile': 'https://Stackoverflow.com/users/5427', 'pm_score': 2, 'selected': False, 'text': '<p>No there is no difference.  In summary:</p>\n\n<p>System.Boolean -> valid values : true, false</p>\n\n<p>bool -> alias for System.Boolean</p>\n\n<p>Nullable&lt;bool&gt; -> valid values : true, false, null</p>\n\n<p>bool? -> alias for Nullable&lt;bool&gt;</p>\n\n<p>Hope this helps.</p>\n'}, {'answer_id': 14610056, 'author': 'svick', 'author_id': 41071, 'author_profile': 'https://Stackoverflow.com/users/41071', 'pm_score': 3, 'selected': False, 'text': "<p>I'm surprised nobody went to the source (the C# spec) yet. From §4.1.10 Nullable types:</p>\n\n<blockquote>\n  <p>A nullable type is written T?, where T is the underlying type. This syntax is shorthand for System.Nullable&lt;T>, and the two forms can be used interchangeably.</p>\n</blockquote>\n\n<p>So, no, there isn't any difference between the two forms. (Assuming you don't have any other type called <code>Nullable&lt;T&gt;</code> in any of the namespaces you use.)</p>\n"}, {'answer_id': 27824497, 'author': 'AMC', 'author_id': 3116561, 'author_profile': 'https://Stackoverflow.com/users/3116561', 'pm_score': 0, 'selected': False, 'text': '<p>No difference. Take a look here: <a href="http://msdn.microsoft.com/en-us/library/1t3y8s4s.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/1t3y8s4s.aspx</a></p>\n\n<p>"The syntax T? is shorthand for Nullable, where T is a value type. The two forms are interchangeable."</p>\n'}]
['https://Stackoverflow.com/questions/56518', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/93/']