Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
659 lines (588 sloc) 38.6 KB
<Type Name="Nullable&lt;T&gt;" FullName="System.Nullable&lt;T&gt;">
<TypeSignature Language="C#" Value="public struct Nullable&lt;T&gt; where T : struct" />
<TypeSignature Language="ILAsm" Value=".class public sequential ansi serializable sealed beforefieldinit Nullable`1&lt;struct .ctor (class System.ValueType) T&gt; extends System.ValueType" />
<TypeSignature Language="DocId" Value="T:System.Nullable`1" />
<TypeSignature Language="VB.NET" Value="Public Structure Nullable(Of T)" />
<TypeSignature Language="C++ CLI" Value="generic &lt;typename T&gt;&#xA; where T : value classpublic value class Nullable" />
<TypeSignature Language="F#" Value="type Nullable&lt;'T (requires 'T : struct)&gt; = struct" />
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.0.20.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>mscorlib</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<TypeParameters>
<TypeParameter Name="T">
<Constraints>
<ParameterAttribute>DefaultConstructorConstraint</ParameterAttribute>
<ParameterAttribute>NotNullableValueTypeConstraint</ParameterAttribute>
<BaseTypeName>System.ValueType</BaseTypeName>
</Constraints>
</TypeParameter>
</TypeParameters>
<Base>
<BaseTypeName>System.ValueType</BaseTypeName>
</Base>
<Interfaces />
<Attributes>
<Attribute FrameworkAlternate="xamarinandroid-7.1;xamarinios-10.8;xamarinmac-3.0">
<AttributeName>System.Diagnostics.DebuggerStepThrough</AttributeName>
</Attribute>
<Attribute FrameworkAlternate="netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;xamarinandroid-7.1;xamarinios-10.8;xamarinmac-3.0">
<AttributeName>System.Serializable</AttributeName>
</Attribute>
</Attributes>
<Docs>
<typeparam name="T">The underlying value type of the <see cref="T:System.Nullable`1" /> generic type.</typeparam>
<summary>Represents a value type that can be assigned <see langword="null" />.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
A type is said to be nullable if it can be assigned a value or can be assigned `null`, which means the type has no value whatsoever. By default, all reference types, such as <xref:System.String>, are nullable, but all value types, such as <xref:System.Int32>, are not.
In C# and Visual Basic, you mark a value type as nullable by using the `?` notation after the value type. For example, `int?` in C# or `Integer?` in Visual Basic declares an integer value type that can be assigned `null`.
The <xref:System.Nullable%601> structure supports using only a value type as a nullable type because reference types are nullable by design.
The <xref:System.Nullable> class provides complementary support for the <xref:System.Nullable%601> structure. The <xref:System.Nullable> class supports obtaining the underlying type of a nullable type, and comparison and equality operations on pairs of nullable types whose underlying value type does not support generic comparison and equality operations.
## Fundamental Properties
The two fundamental members of the <xref:System.Nullable%601> structure are the <xref:System.Nullable%601.HasValue%2A> and <xref:System.Nullable%601.Value%2A> properties. If the <xref:System.Nullable%601.HasValue%2A> property for a <xref:System.Nullable%601> object is `true`, the value of the object can be accessed with the <xref:System.Nullable%601.Value%2A> property. If the <xref:System.Nullable%601.HasValue%2A> property is `false`, the value of the object is undefined and an attempt to access the <xref:System.Nullable%601.Value%2A> property throws an <xref:System.InvalidOperationException>.
## Boxing and Unboxing
When a nullable type is boxed, the common language runtime automatically boxes the underlying value of the <xref:System.Nullable%601> object, not the <xref:System.Nullable%601> object itself. That is, if the <xref:System.Nullable%601.HasValue%2A> property is `true`, the contents of the <xref:System.Nullable%601.Value%2A> property is boxed. When the underlying value of a nullable type is unboxed, the common language runtime creates a new <xref:System.Nullable%601> structure initialized to the underlying value.
If the `HasValue` property of a nullable type is `false`, the result of a boxing operation is `null`. Consequently, if a boxed nullable type is passed to a method that expects an object argument, that method must be prepared to handle the case where the argument is `null`. When `null` is unboxed into a nullable type, the common language runtime creates a new <xref:System.Nullable%601> structure and initializes its `HasValue` property to `false`.
## [!INCLUDE[net_v451](~/includes/net-v451-md.md)] and Windows Runtime Components
Starting with the [!INCLUDE[net_v451](~/includes/net-v451-md.md)], you can include a <xref:System.Nullable%601> type as a member of a structure exported in a WinMD library. Previously, this was not supported.
## Examples
The following code example defines three rows of a table in the Microsoft Pubs sample database. The table contains two columns that are not nullable and two columns that are nullable.
[!code-cpp[system.nullableOfT.class#1](~/samples/snippets/cpp/VS_Snippets_CLR_System/system.nullableOfT.class/cpp/tarow.cpp#1)]
[!code-csharp[system.nullableOfT.class#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.nullableOfT.class/cs/tarow.cs#1)]
[!code-vb[system.nullableOfT.class#1](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.nullableOfT.class/vb/tarow.vb#1)]
]]></format>
</remarks>
<altmember cref="T:System.Nullable" />
<related type="Article" href="https://msdn.microsoft.com/library/e473cb01-28ca-42be-9cea-f717055d72c6">Nullable Types (C# Programming Guide)</related>
<related type="Article" href="https://msdn.microsoft.com/library/9ac3b602-6f96-4e6d-96f7-cd4e81c468a6">Nullable Value Types (Visual Basic)</related>
</Docs>
<Members>
<Member MemberName=".ctor">
<MemberSignature Language="C#" Value="public Nullable (T value);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig specialname rtspecialname instance void .ctor(!T value) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Nullable`1.#ctor(`0)" />
<MemberSignature Language="VB.NET" Value="Public Sub New (value As T)" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; Nullable(T value);" />
<MemberSignature Language="F#" Value="new Nullable&lt;'T (requires 'T : struct)&gt; : 'T -&gt; Nullable&lt;'T (requires 'T : struct)&gt;" Usage="new System.Nullable&lt;'T (requires 'T : struct)&gt; value" />
<MemberType>Constructor</MemberType>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.0.20.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>mscorlib</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2">
<AttributeName>System.Runtime.TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")</AttributeName>
</Attribute>
</Attributes>
<Parameters>
<Parameter Name="value" Type="T" />
</Parameters>
<Docs>
<param name="value">A value type.</param>
<summary>Initializes a new instance of the <see cref="T:System.Nullable`1" /> structure to the specified value.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The <xref:System.Nullable%601.%23ctor%2A> constructor initializes the <xref:System.Nullable%601.HasValue%2A> property of the new <xref:System.Nullable%601> object to `true`, and the <xref:System.Nullable%601.Value%2A> property to the value of the `value` parameter.
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="Equals">
<MemberSignature Language="C#" Value="public override bool Equals (object other);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig virtual instance bool Equals(object other) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Nullable`1.Equals(System.Object)" />
<MemberSignature Language="VB.NET" Value="Public Overrides Function Equals (other As Object) As Boolean" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; override bool Equals(System::Object ^ other);" />
<MemberSignature Language="F#" Value="override this.Equals : obj -&gt; bool" Usage="nullable.Equals other" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.0.20.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>mscorlib</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Boolean</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="other" Type="System.Object" />
</Parameters>
<Docs>
<param name="other">An object.</param>
<summary>Indicates whether the current <see cref="T:System.Nullable`1" /> object is equal to a specified object.</summary>
<returns>
<see langword="true" /> if the <paramref name="other" /> parameter is equal to the current <see cref="T:System.Nullable`1" /> object; otherwise, <see langword="false" />.
This table describes how equality is defined for the compared values:
<list type="table"><listheader><term> Return Value
</term><description> Description
</description></listheader><item><term><see langword="true" /></term><description> The <see cref="P:System.Nullable`1.HasValue" /> property is <see langword="false" />, and the <paramref name="other" /> parameter is <see langword="null" />. That is, two null values are equal by definition.
-or-
The <see cref="P:System.Nullable`1.HasValue" /> property is <see langword="true" />, and the value returned by the <see cref="P:System.Nullable`1.Value" /> property is equal to the <paramref name="other" /> parameter.
</description></item><item><term><see langword="false" /></term><description> The <see cref="P:System.Nullable`1.HasValue" /> property for the current <see cref="T:System.Nullable`1" /> structure is <see langword="true" />, and the <paramref name="other" /> parameter is <see langword="null" />.
-or-
The <see cref="P:System.Nullable`1.HasValue" /> property for the current <see cref="T:System.Nullable`1" /> structure is <see langword="false" />, and the <paramref name="other" /> parameter is not <see langword="null" />.
-or-
The <see cref="P:System.Nullable`1.HasValue" /> property for the current <see cref="T:System.Nullable`1" /> structure is <see langword="true" />, and the value returned by the <see cref="P:System.Nullable`1.Value" /> property is not equal to the <paramref name="other" /> parameter.
</description></item></list></returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
If the <xref:System.Nullable%601.HasValue%2A> property of the current <xref:System.Nullable%601> structure is `true` and the `other` argument is not `null`, equality is determined by passing the `other` parameter to the `Equals` method of the underlying value of the current <xref:System.Nullable%601> structure.
## Examples
The following code example determines whether an object and a <xref:System.Nullable%601> object are equal to the current <xref:System.Nullable%601> object.
[!code-csharp[system.nullableOfT.Equals#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.nullableOfT.Equals/cs/eq.cs#1)]
[!code-vb[system.nullableOfT.Equals#1](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.nullableOfT.Equals/vb/eq.vb#1)]
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="GetHashCode">
<MemberSignature Language="C#" Value="public override int GetHashCode ();" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig virtual instance int32 GetHashCode() cil managed" />
<MemberSignature Language="DocId" Value="M:System.Nullable`1.GetHashCode" />
<MemberSignature Language="VB.NET" Value="Public Overrides Function GetHashCode () As Integer" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; override int GetHashCode();" />
<MemberSignature Language="F#" Value="override this.GetHashCode : unit -&gt; int" Usage="nullable.GetHashCode " />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.0.20.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>mscorlib</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Int32</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>Retrieves the hash code of the object returned by the <see cref="P:System.Nullable`1.Value" /> property.</summary>
<returns>The hash code of the object returned by the <see cref="P:System.Nullable`1.Value" /> property if the <see cref="P:System.Nullable`1.HasValue" /> property is <see langword="true" />, or zero if the <see cref="P:System.Nullable`1.HasValue" /> property is <see langword="false" />.</returns>
<remarks>To be added.</remarks>
</Docs>
</Member>
<MemberGroup MemberName="GetValueOrDefault">
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.0.20.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
</AssemblyInfo>
<Docs>
<summary>Retrieves the value of the current <see cref="T:System.Nullable`1" /> object, or a default value.</summary>
</Docs>
</MemberGroup>
<Member MemberName="GetValueOrDefault">
<MemberSignature Language="C#" Value="public T GetValueOrDefault ();" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig instance !T GetValueOrDefault() cil managed" />
<MemberSignature Language="DocId" Value="M:System.Nullable`1.GetValueOrDefault" />
<MemberSignature Language="VB.NET" Value="Public Function GetValueOrDefault () As T" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; T GetValueOrDefault();" />
<MemberSignature Language="F#" Value="member this.GetValueOrDefault : unit -&gt; 'T" Usage="nullable.GetValueOrDefault " />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.0.20.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>mscorlib</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2">
<AttributeName>System.Runtime.TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>T</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>Retrieves the value of the current <see cref="T:System.Nullable`1" /> object, or the default value of the underlying type.</summary>
<returns>The value of the <see cref="P:System.Nullable`1.Value" /> property if the <see cref="P:System.Nullable`1.HasValue" /> property is <see langword="true" />; otherwise, the default value of the underlying type.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The <xref:System.Nullable%601.GetValueOrDefault%2A> method returns a value even if the <xref:System.Nullable%601.HasValue%2A> property is `false` (unlike the <xref:System.Nullable%601.Value%2A> property, which throws an exception). If the <xref:System.Nullable%601.HasValue%2A> property is `false`, the method returns the [default](~/docs/csharp/language-reference/keywords/default-values-table.md) value of the underlying type.
## Examples
The following code example retrieves the value of a <xref:System.Nullable%601> object if that value is defined; otherwise, it retrieves the default value or a specific default value.
[!code-csharp[system.nullableOfT.GetValueOrDefault#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.nullableOfT.GetValueOrDefault/cs/gvod.cs#1)]
[!code-vb[system.nullableOfT.GetValueOrDefault#1](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.nullableOfT.GetValueOrDefault/vb/gvod.vb#1)]
]]></format>
</remarks>
<altmember cref="M:System.Nullable`1.GetValueOrDefault(`0)" />
</Docs>
</Member>
<Member MemberName="GetValueOrDefault">
<MemberSignature Language="C#" Value="public T GetValueOrDefault (T defaultValue);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig instance !T GetValueOrDefault(!T defaultValue) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Nullable`1.GetValueOrDefault(`0)" />
<MemberSignature Language="VB.NET" Value="Public Function GetValueOrDefault (defaultValue As T) As T" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; T GetValueOrDefault(T defaultValue);" />
<MemberSignature Language="F#" Value="member this.GetValueOrDefault : 'T -&gt; 'T" Usage="nullable.GetValueOrDefault defaultValue" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.0.20.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>mscorlib</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>T</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="defaultValue" Type="T" />
</Parameters>
<Docs>
<param name="defaultValue">A value to return if the <see cref="P:System.Nullable`1.HasValue" /> property is <see langword="false" />.</param>
<summary>Retrieves the value of the current <see cref="T:System.Nullable`1" /> object, or the specified default value.</summary>
<returns>The value of the <see cref="P:System.Nullable`1.Value" /> property if the <see cref="P:System.Nullable`1.HasValue" /> property is <see langword="true" />; otherwise, the <paramref name="defaultValue" /> parameter.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The <xref:System.Nullable%601.GetValueOrDefault%2A> method returns a value even if the <xref:System.Nullable%601.HasValue%2A> property is `false` (unlike the <xref:System.Nullable%601.Value%2A> property, which throws an exception).
## Examples
The following code example retrieves the value of a <xref:System.Nullable%601> object if that value is defined; otherwise, it retrieves the default value or a specific default value.
[!code-csharp[system.nullableOfT.GetValueOrDefault#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.nullableOfT.GetValueOrDefault/cs/gvod.cs#1)]
[!code-vb[system.nullableOfT.GetValueOrDefault#1](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.nullableOfT.GetValueOrDefault/vb/gvod.vb#1)]
]]></format>
</remarks>
<altmember cref="M:System.Nullable`1.GetValueOrDefault" />
</Docs>
</Member>
<Member MemberName="HasValue">
<MemberSignature Language="C#" Value="public bool HasValue { get; }" />
<MemberSignature Language="ILAsm" Value=".property instance bool HasValue" />
<MemberSignature Language="DocId" Value="P:System.Nullable`1.HasValue" />
<MemberSignature Language="VB.NET" Value="Public ReadOnly Property HasValue As Boolean" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; property bool HasValue { bool get(); };" />
<MemberSignature Language="F#" Value="member this.HasValue : bool" Usage="System.Nullable&lt;'T (requires 'T : struct)&gt;.HasValue" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.0.20.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>mscorlib</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Boolean</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets a value indicating whether the current <see cref="T:System.Nullable`1" /> object has a valid value of its underlying type.</summary>
<value>
<see langword="true" /> if the current <see cref="T:System.Nullable`1" /> object has a value; <see langword="false" /> if the current <see cref="T:System.Nullable`1" /> object has no value.</value>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
If the <xref:System.Nullable%601.HasValue%2A> property is `true`, the value of the current <xref:System.Nullable%601> object can be accessed with the <xref:System.Nullable%601.Value%2A> property. Otherwise, attempting to access its value throws an <xref:System.InvalidOperationException> exception.
## Examples
The following example uses the <xref:System.Nullable%601.HasValue%2A> property of a `Nullable<int>` (`Nullable(Of Integer)` in Visual Basic) object to determine whether it should display the object's <xref:System.Nullable%601.Value%2A> property or its <xref:System.Nullable%601.GetValueOrDefault%2A> property.
[!code-csharp[System.Nullable~1.HasValue#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.nullable~1.hasvalue/cs/hasvalue2.cs#1)]
[!code-vb[System.Nullable~1.HasValue#1](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.nullable~1.hasvalue/vb/hasvalue2.vb#1)]
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="op_Explicit">
<MemberSignature Language="C#" Value="public static explicit operator T (Nullable&lt;T&gt; value);" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig specialname !T op_Explicit(valuetype System.Nullable`1&lt;!T&gt; value) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Nullable`1.op_Explicit(System.Nullable{`0})~`0" />
<MemberSignature Language="VB.NET" Value="Public Shared Narrowing Operator CType (value As Nullable(Of T)) As T" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; static explicit operator T(Nullable&lt;T&gt; value);" />
<MemberSignature Language="F#" Value="static member op_Explicit : Nullable&lt;'T (requires 'T : struct)&gt; -&gt; 'T" Usage="System.Nullable&lt;'T (requires 'T : struct)&gt;.op_Explicit value" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.0.20.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>mscorlib</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>T</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="value" Type="System.Nullable&lt;T&gt;" />
</Parameters>
<Docs>
<param name="value">A nullable value.</param>
<summary>Defines an explicit conversion of a <see cref="T:System.Nullable`1" /> instance to its underlying value.</summary>
<returns>The value of the <see cref="P:System.Nullable`1.Value" /> property for the <paramref name="value" /> parameter.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
This operator supports the explicit conversion of the current <xref:System.Nullable%601> instance to type `T`, the type of <xref:System.Nullable%601.Value%2A>. The syntax for such explicit conversions is language-dependent. You may also be able to perform the conversion by calling the <xref:System.Convert.ChangeType%2A?displayProperty=nameWithType> method.
The equivalent method for this operator is <xref:System.Nullable%601.Value?displayProperty=nameWithType>
## Examples
The <xref:System.Nullable%601.op_Explicit%2A> operator enables code such as the following, which converts a `Nullable(Of Int32)` value to an <xref:System.Int32> value.
[!code-csharp[System.Nullable~1.Conversion#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.nullable~1.conversion/cs/explicit1.cs#1)]
[!code-vb[System.Nullable~1.Conversion#1](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.nullable~1.conversion/vb/explicit1.vb#1)]
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="op_Implicit">
<MemberSignature Language="C#" Value="public static implicit operator Nullable&lt;T&gt; (T value);" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig specialname valuetype System.Nullable`1&lt;!T&gt; op_Implicit(!T value) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Nullable`1.op_Implicit(`0)~System.Nullable{`0}" />
<MemberSignature Language="VB.NET" Value="Public Shared Widening Operator CType (value As T) As Nullable(Of T)" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; static operator Nullable&lt;T&gt;(T value);" />
<MemberSignature Language="F#" Value="static member op_Implicit : 'T -&gt; Nullable&lt;'T (requires 'T : struct)&gt;" Usage="System.Nullable&lt;'T (requires 'T : struct)&gt;.op_Implicit value" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.0.20.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>mscorlib</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Nullable&lt;T&gt;</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="value" Type="T" />
</Parameters>
<Docs>
<param name="value">A value type.</param>
<summary>Creates a new <see cref="T:System.Nullable`1" /> object initialized to a specified value.</summary>
<returns>A <see cref="T:System.Nullable`1" /> object whose <see cref="P:System.Nullable`1.Value" /> property is initialized with the <paramref name="value" /> parameter.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
If the `value` parameter is not `null`, the <xref:System.Nullable%601.Value%2A> property of the new <xref:System.Nullable%601> value is initialized to the `value` parameter and the <xref:System.Nullable%601.HasValue%2A> property is initialized to `true`.
If the `value` parameter is `null`, the <xref:System.Nullable%601.Value%2A> property of the new <xref:System.Nullable%601> value is initialized to the default value, which is the value that is all binary zeroes, and the <xref:System.Nullable%601.HasValue%2A> property is initialized to `false`.
The equivalent method for this operator is <xref:System.Nullable%601.%23ctor%28%600%29?displayProperty=nameWithType>]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="ToString">
<MemberSignature Language="C#" Value="public override string ToString ();" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig virtual instance string ToString() cil managed" />
<MemberSignature Language="DocId" Value="M:System.Nullable`1.ToString" />
<MemberSignature Language="VB.NET" Value="Public Overrides Function ToString () As String" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; override System::String ^ ToString();" />
<MemberSignature Language="F#" Value="override this.ToString : unit -&gt; string" Usage="nullable.ToString " />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.0.20.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>mscorlib</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.String</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>Returns the text representation of the value of the current <see cref="T:System.Nullable`1" /> object.</summary>
<returns>The text representation of the value of the current <see cref="T:System.Nullable`1" /> object if the <see cref="P:System.Nullable`1.HasValue" /> property is <see langword="true" />, or an empty string ("") if the <see cref="P:System.Nullable`1.HasValue" /> property is <see langword="false" />.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The <xref:System.Nullable%601.ToString%2A> property returns the string yielded by calling the `ToString` property of the object returned by the <xref:System.Nullable%601.Value%2A> property.
## Examples
The following code example displays the value of the current <xref:System.Nullable%601> object.
[!code-csharp[system.nullableOfT.ToString#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.nullableOfT.ToString/cs/ts.cs#1)]
[!code-vb[system.nullableOfT.ToString#1](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.nullableOfT.ToString/vb/ts.vb#1)]
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="Value">
<MemberSignature Language="C#" Value="public T Value { get; }" />
<MemberSignature Language="ILAsm" Value=".property instance !T Value" />
<MemberSignature Language="DocId" Value="P:System.Nullable`1.Value" />
<MemberSignature Language="VB.NET" Value="Public ReadOnly Property Value As T" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; property T Value { T get(); };" />
<MemberSignature Language="F#" Value="member this.Value : 'T" Usage="System.Nullable&lt;'T (requires 'T : struct)&gt;.Value" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.0.20.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>mscorlib</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2">
<AttributeName>get: System.Runtime.TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>T</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets the value of the current <see cref="T:System.Nullable`1" /> object if it has been assigned a valid underlying value.</summary>
<value>The value of the current <see cref="T:System.Nullable`1" /> object if the <see cref="P:System.Nullable`1.HasValue" /> property is <see langword="true" />. An exception is thrown if the <see cref="P:System.Nullable`1.HasValue" /> property is <see langword="false" />.</value>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
If a value of type `T` has not been assigned to the <xref:System.Nullable%601> object, you can compare it to `null` and retrieve its <xref:System.Nullable%601.HasValue%2A> property, but you cannot access its <xref:System.Nullable%601.Value%2A> property or call its other members.
## Examples
The following example uses the <xref:System.Nullable%601.HasValue%2A> property of a `Nullable<int>` (`Nullable(Of Integer)` in Visual Basic) object to determine whether it should display the object's <xref:System.Nullable%601.Value%2A> property or its <xref:System.Nullable%601.GetValueOrDefault%2A> property.
[!code-csharp[System.Nullable~1.HasValue#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.nullable~1.hasvalue/cs/hasvalue2.cs#1)]
[!code-vb[System.Nullable~1.HasValue#1](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.nullable~1.hasvalue/vb/hasvalue2.vb#1)]
]]></format>
</remarks>
<exception cref="T:System.InvalidOperationException">The <see cref="P:System.Nullable`1.HasValue" /> property is <see langword="false" />.</exception>
</Docs>
</Member>
</Members>
</Type>
You can’t perform that action at this time.