<p>I have a nullable property, and I want to return a null value. How do I do that in VB.NET ?</p>

<p>Currently I use this solution, but I think there might be a better way.</p>

<pre><code>    Public Shared ReadOnly Property rubrique_id() As Nullable(Of Integer)
        Get
            If Current.Request.QueryString("rid") &lt;&gt; "" Then
                Return CInt(Current.Request.QueryString("rid"))
            Else
                Return (New Nullable(Of Integer)).Value
            End If
        End Get
    End Property
</code></pre>

[{'answer_id': 72465, 'author': 'Jon', 'author_id': 12261, 'author_profile': 'https://Stackoverflow.com/users/12261', 'pm_score': 4, 'selected': True, 'text': '<p>Are you looking for the keyword "Nothing"?</p>\n'}, {'answer_id': 72542, 'author': 'Luca Molteni', 'author_id': 4206, 'author_profile': 'https://Stackoverflow.com/users/4206', 'pm_score': 2, 'selected': False, 'text': '<p>Yes, it\'s Nothing in VB.NET, or null in C#.</p>\n\n<p>The Nullable generic datatype give the compiler the possibility to assign a "Nothing" (or null" value to a value type. Without explicitally writing it, you can\'t do it.</p>\n\n<p><a href="http://msdn.microsoft.com/en-us/library/1t3y8s4s(VS.80).aspx" rel="nofollow noreferrer">Nullable Types in C#</a></p>\n'}, {'answer_id': 78272, 'author': 'gregmac', 'author_id': 7913, 'author_profile': 'https://Stackoverflow.com/users/7913', 'pm_score': 1, 'selected': False, 'text': '<pre><code>Public Shared ReadOnly Property rubrique_id() As Nullable(Of Integer)\n    Get\n        If Current.Request.QueryString("rid") &lt;&gt; "" Then\n            Return CInt(Current.Request.QueryString("rid"))\n        Else\n            Return Nothing\n        End If\n    End Get\nEnd Property\n</code></pre>\n'}, {'answer_id': 439923, 'author': 'Barbaros Alp', 'author_id': 51734, 'author_profile': 'https://Stackoverflow.com/users/51734', 'pm_score': 0, 'selected': False, 'text': '<p>Or this is the way i use, to be honest ReSharper has taught me :)</p>\n\n<pre><code>finder.Advisor = ucEstateFinder.Advisor == "-1" ? (long?)null : long.Parse(ucEstateFinder.Advisor);\n</code></pre>\n\n<p>On the assigning above if i directly assign null to finder.Advisor*(long?)* there would be no problem. But if i try to use if clause i need to cast it like that <code>(long?)null</code>.</p>\n'}, {'answer_id': 21494597, 'author': 'Mark Hurd', 'author_id': 256431, 'author_profile': 'https://Stackoverflow.com/users/256431', 'pm_score': 0, 'selected': False, 'text': '<p>Although <code>Nothing</code> can be used, your "existing" code is almost correct; just don\'t attempt to get the <code>.Value</code>:</p>\n\n<pre><code>Public Shared ReadOnly Property rubrique_id() As Nullable(Of Integer)\n    Get\n        If Current.Request.QueryString("rid") &lt;&gt; "" Then\n            Return CInt(Current.Request.QueryString("rid"))\n        Else\n            Return New Nullable(Of Integer)\n        End If\n    End Get\nEnd Property\n</code></pre>\n\n<p>This then becomes the simplest solution if you happen to want to reduce it to a <code>If</code> expression:</p>\n\n<pre><code>Public Shared ReadOnly Property rubrique_id() As Nullable(Of Integer)\n    Get\n        Return If(Current.Request.QueryString("rid") &lt;&gt; "", _\n            CInt(Current.Request.QueryString("rid")), _\n            New Nullable(Of Integer))\n    End Get\nEnd Property\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/72442', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/6776/']