Breyta

Deila með


XElement.Explicit Operator

Definition

Overloads

Explicit(XElement to Nullable<Int64>)

Cast the value of this XElement to a Nullable<T> of Int64.

Explicit(XElement to Nullable<Single>)

Cast the value of this XElement to a Nullable<T> of Single.

Explicit(XElement to Nullable<TimeSpan>)

Cast the value of this XElement to a Nullable<T> of TimeSpan.

Explicit(XElement to Nullable<UInt32>)

Cast the value of this XElement to a Nullable<T> of UInt32.

Explicit(XElement to Nullable<UInt64>)

Cast the value of this XElement to a Nullable<T> of UInt64.

Explicit(XElement to UInt32)

Cast the value of this XElement to a UInt32.

Explicit(XElement to String)

Cast the value of this XElement to a String.

Explicit(XElement to TimeSpan)

Cast the value of this XElement to a TimeSpan.

Explicit(XElement to UInt64)

Cast the value of this XElement to a UInt64.

Explicit(XElement to Nullable<Int32>)

Cast the value of this XElement to a Nullable<T> of Int32.

Explicit(XElement to Single)

Cast the value of this XElement to a Single.

Explicit(XElement to Nullable<Guid>)

Cast the value of this XElement to a Nullable<T> of Guid.

Explicit(XElement to Nullable<Boolean>)

Cast the value of this XElement to a Nullable<T> of Boolean.

Explicit(XElement to Nullable<Decimal>)

Cast the value of this XElement to a Nullable<T> of Decimal.

Explicit(XElement to Boolean)

Cast the value of this XElement to a Boolean.

Explicit(XElement to DateTime)

Cast the value of this XElement to a DateTime.

Explicit(XElement to DateTimeOffset)

Cast the value of this XAttribute to a DateTimeOffset.

Explicit(XElement to Double)

Cast the value of this XElement to a Double.

Explicit(XElement to Guid)

Cast the value of this XElement to a Guid.

Explicit(XElement to Decimal)

Cast the value of this XElement to a Decimal.

Explicit(XElement to Int64)

Cast the value of this XElement to an Int64.

Explicit(XElement to Nullable<Double>)

Cast the value of this XElement to a Nullable<T> of Double.

Explicit(XElement to Nullable<DateTime>)

Cast the value of this XElement to a Nullable<T> of DateTime.

Explicit(XElement to Nullable<DateTimeOffset>)

Cast the value of this XElement to a Nullable<T> of DateTimeOffset.

Explicit(XElement to Int32)

Cast the value of this XElement to an Int32.

Explicit(XElement to Nullable<Int64>)

Source:
XElement.cs
Source:
XElement.cs
Source:
XElement.cs

Important

This API is not CLS-compliant.

Cast the value of this XElement to a Nullable<T> of Int64.

public:
 static explicit operator Nullable<long>(System::Xml::Linq::XElement ^ element);
[System.CLSCompliant(false)]
public static explicit operator long? (System.Xml.Linq.XElement element);
[System.CLSCompliant(false)]
public static explicit operator long? (System.Xml.Linq.XElement? element);
[<System.CLSCompliant(false)>]
static member op_Explicit : System.Xml.Linq.XElement -> Nullable<int64>
Public Shared Narrowing Operator CType (element As XElement) As Nullable(Of Long)

Parameters

element
XElement

The XElement to cast to Nullable<T> of Int64.

Returns

A Nullable<T> of Int64 that contains the content of this XElement.

Attributes

Exceptions

The element is not null and does not contain a valid Int64 value.

Examples

The following example creates an element with long integer content. It then retrieves the value by casting to Nullable<T> of Int64.

XElement root = new XElement("Root",
    new XElement("Value", 9223372036854775807)
);
ulong? value = (ulong?)root.Element("Value");
Console.WriteLine("Nullable ulong: value={0}", value == null ? "null" : value.ToString());
Dim root As XElement = _
        <Root>
            <Value>9223372036854775807</Value>
        </Root>
Dim value As Nullable(Of ULong) = CType(root.Element("Value"), Nullable(Of ULong))
Console.WriteLine("Nullable ulong: value={0}", IIf(value.HasValue, value.ToString(), "null"))

This example produces the following output:

Nullable ulong: value=9223372036854775807

See also

Applies to

Explicit(XElement to Nullable<Single>)

Source:
XElement.cs
Source:
XElement.cs
Source:
XElement.cs

Important

This API is not CLS-compliant.

Cast the value of this XElement to a Nullable<T> of Single.

public:
 static explicit operator Nullable<float>(System::Xml::Linq::XElement ^ element);
[System.CLSCompliant(false)]
public static explicit operator float? (System.Xml.Linq.XElement element);
[System.CLSCompliant(false)]
public static explicit operator float? (System.Xml.Linq.XElement? element);
[<System.CLSCompliant(false)>]
static member op_Explicit : System.Xml.Linq.XElement -> Nullable<single>
Public Shared Narrowing Operator CType (element As XElement) As Nullable(Of Single)

Parameters

element
XElement

The XElement to cast to Nullable<T> of Single.

Returns

A Nullable<T> of Single that contains the content of this XElement.

Attributes

Exceptions

The element is not null and does not contain a valid Single value.

Examples

The following example creates an element with single precision floating point content. It then retrieves the value by casting to Nullable<T> of Single.

XElement root = new XElement("Root",
    new XElement("Value", 3.402823e38)
);
float? value = (float?)root.Element("Value");
Console.WriteLine("Nullable Single: value={0}", value == null ? "null" : value.ToString());
Dim root As XElement = _
        <Root>
            <Value>3.402823e38</Value>
        </Root>
Dim value As Nullable(Of Single) = CType(root.Element("Value"), Nullable(Of Single))
Console.WriteLine("Nullable Single: value={0}", IIf(value.HasValue, value.ToString(), "null"))

This example produces the following output:

Nullable Single: value=3.402823E+38

See also

Applies to

Explicit(XElement to Nullable<TimeSpan>)

Source:
XElement.cs
Source:
XElement.cs
Source:
XElement.cs

Important

This API is not CLS-compliant.

Cast the value of this XElement to a Nullable<T> of TimeSpan.

public:
 static explicit operator Nullable<TimeSpan>(System::Xml::Linq::XElement ^ element);
[System.CLSCompliant(false)]
public static explicit operator TimeSpan? (System.Xml.Linq.XElement element);
[System.CLSCompliant(false)]
public static explicit operator TimeSpan? (System.Xml.Linq.XElement? element);
[<System.CLSCompliant(false)>]
static member op_Explicit : System.Xml.Linq.XElement -> Nullable<TimeSpan>
Public Shared Narrowing Operator CType (element As XElement) As Nullable(Of TimeSpan)

Parameters

element
XElement

The XElement to cast to Nullable<T> of TimeSpan.

Returns

A Nullable<T> of TimeSpan that contains the content of this XElement.

Attributes

Exceptions

The element is not null and does not contain a valid TimeSpan value.

Examples

The following example creates an element with time span content. It then retrieves the value by casting to Nullable<T> of TimeSpan.

XElement root = new XElement("Root",
    new XElement("Value", new TimeSpan(1, 5, 30))
);
TimeSpan? value = (TimeSpan?)root.Element("Value");
Console.WriteLine("Nullable TimeSpan: value={0}", value == null ? "null" : value.ToString());
Dim root As XElement = _
    <Root>
        <Value><%= New TimeSpan(1, 5, 30) %></Value>
    </Root>
Dim value As Nullable(Of TimeSpan) = CType(root.Element("Value"), Nullable(Of TimeSpan))
Console.WriteLine("Nullable TimeSpan: value={0}", IIf(value.HasValue, value.ToString(), "null"))

This example produces the following output:

Nullable TimeSpan: value=01:05:30

Remarks

The value space of an attribute or element that contains time span content is closely related to duration content as described in ISO 8601. When creating an attribute or element that contains time span content, the attribute or element values are formatted per the W3C specification. Please see the W3C specification for more details.

Behavior is lax when casting to a Nullable<T> of TimeSpan from an attribute or element. Even if the attribute or element value is not formatted exactly per the W3C specification, the value is appropriately converted to a Nullable<T> of TimeSpan.

See also

Applies to

Explicit(XElement to Nullable<UInt32>)

Source:
XElement.cs
Source:
XElement.cs
Source:
XElement.cs

Important

This API is not CLS-compliant.

Cast the value of this XElement to a Nullable<T> of UInt32.

public:
 static explicit operator Nullable<System::UInt32>(System::Xml::Linq::XElement ^ element);
[System.CLSCompliant(false)]
public static explicit operator uint? (System.Xml.Linq.XElement element);
[System.CLSCompliant(false)]
public static explicit operator uint? (System.Xml.Linq.XElement? element);
[<System.CLSCompliant(false)>]
static member op_Explicit : System.Xml.Linq.XElement -> Nullable<uint32>
Public Shared Narrowing Operator CType (element As XElement) As Nullable(Of UInteger)

Parameters

element
XElement

The XElement to cast to Nullable<T> of UInt32.

Returns

A Nullable<T> of UInt32 that contains the content of this XElement.

Attributes

Exceptions

The element is not null and does not contain a valid UInt32 value.

Examples

The following example creates an element with unsigned integer content. It then retrieves the value by casting to Nullable<T> of UInt32.

XElement root = new XElement("Root",
    new XElement("Value", 4294967295)
);
uint? value = (uint?)root.Element("Value");
Console.WriteLine("Nullable uint: value={0}", value == null ? "null" : value.ToString());
Dim root As XElement = _
        <Root>
            <Value>4294967295</Value>
        </Root>
Dim value As Nullable(Of UInteger) = CType(root.Element("Value"), Nullable(Of UInteger))
Console.WriteLine("Nullable uint: value={0}", IIf(value.HasValue, value.ToString(), "null"))

This example produces the following output:

Nullable uint: value=4294967295

See also

Applies to

Explicit(XElement to Nullable<UInt64>)

Source:
XElement.cs
Source:
XElement.cs
Source:
XElement.cs

Important

This API is not CLS-compliant.

Cast the value of this XElement to a Nullable<T> of UInt64.

public:
 static explicit operator Nullable<System::UInt64>(System::Xml::Linq::XElement ^ element);
[System.CLSCompliant(false)]
public static explicit operator ulong? (System.Xml.Linq.XElement element);
[System.CLSCompliant(false)]
public static explicit operator ulong? (System.Xml.Linq.XElement? element);
[<System.CLSCompliant(false)>]
static member op_Explicit : System.Xml.Linq.XElement -> Nullable<uint64>
Public Shared Narrowing Operator CType (element As XElement) As Nullable(Of ULong)

Parameters

element
XElement

The XElement to cast to Nullable<T> of UInt64.

Returns

A Nullable<T> of UInt64 that contains the content of this XElement.

Attributes

Exceptions

The element is not null and does not contain a valid UInt64 value.

Examples

The following example creates an element with unsigned long integer content. It then retrieves the value by casting to Nullable<T> of UInt64.

XElement root = new XElement("Root",
    new XElement("Value", 9223372036854775807)
);
ulong? value = (ulong?)root.Element("Value");
Console.WriteLine("Nullable ulong: value={0}", value == null ? "null" : value.ToString());
Dim root As XElement = _
        <Root>
            <Value>9223372036854775807</Value>
        </Root>

Dim value As Nullable(Of ULong) = CType(root.Element("Value"), Nullable(Of ULong))
Console.WriteLine("Nullable ulong: value={0}", IIf(value.HasValue, value.ToString(), "null"))

This example produces the following output:

Nullable ulong: value=9223372036854775807

See also

Applies to

Explicit(XElement to UInt32)

Source:
XElement.cs
Source:
XElement.cs
Source:
XElement.cs

Important

This API is not CLS-compliant.

Cast the value of this XElement to a UInt32.

public:
 static explicit operator System::UInt32(System::Xml::Linq::XElement ^ element);
[System.CLSCompliant(false)]
public static explicit operator uint (System.Xml.Linq.XElement element);
[<System.CLSCompliant(false)>]
static member op_Explicit : System.Xml.Linq.XElement -> uint32
Public Shared Narrowing Operator CType (element As XElement) As UInteger

Parameters

element
XElement

The XElement to cast to UInt32.

Returns

A UInt32 that contains the content of this XElement.

Attributes

Exceptions

The element does not contain a valid UInt32 value.

The element parameter is null.

Examples

The following example creates an element with unsigned integer content. It then retrieves the value by casting to UInt32.

XElement root = new XElement("Root", 4294967295);
uint value = (uint)root;
Console.WriteLine("value={0}", value);
Dim root As XElement = <Root>4294967295</Root>
Dim value As UInteger = CUInt(root)
Console.WriteLine("value={0}", value)

This example produces the following output:

value=4294967295

See also

Applies to

Explicit(XElement to String)

Source:
XElement.cs
Source:
XElement.cs
Source:
XElement.cs

Important

This API is not CLS-compliant.

Cast the value of this XElement to a String.

public:
 static explicit operator System::String ^(System::Xml::Linq::XElement ^ element);
[System.CLSCompliant(false)]
public static explicit operator string (System.Xml.Linq.XElement element);
[System.CLSCompliant(false)]
public static explicit operator string? (System.Xml.Linq.XElement? element);
[<System.CLSCompliant(false)>]
static member op_Explicit : System.Xml.Linq.XElement -> string
Public Shared Narrowing Operator CType (element As XElement) As String

Parameters

element
XElement

The XElement to cast to String.

Returns

A String that contains the content of this XElement.

Attributes

Examples

The following example creates an element with string content. It then retrieves the value by casting to String.

XElement root = XElement.Parse("<Root>abc <b>def </b>ghi</Root>");
Console.WriteLine("(string)root={0}", (string)root);
Dim root As XElement = <Root>abc <b>def </b>ghi</Root>
Console.WriteLine("(string)root={0}", root.Value)

This example produces the following output:

(string)root=abc def ghi

Remarks

If the XElement has children, the concatenated string value of all of the element's text and descendant's text is returned.

See also

Applies to

Explicit(XElement to TimeSpan)

Source:
XElement.cs
Source:
XElement.cs
Source:
XElement.cs

Important

This API is not CLS-compliant.

Cast the value of this XElement to a TimeSpan.

public:
 static explicit operator TimeSpan(System::Xml::Linq::XElement ^ element);
[System.CLSCompliant(false)]
public static explicit operator TimeSpan (System.Xml.Linq.XElement element);
[<System.CLSCompliant(false)>]
static member op_Explicit : System.Xml.Linq.XElement -> TimeSpan
Public Shared Narrowing Operator CType (element As XElement) As TimeSpan

Parameters

element
XElement

The XElement to cast to TimeSpan.

Returns

A TimeSpan that contains the content of this XElement.

Attributes

Exceptions

The element does not contain a valid TimeSpan value.

The element parameter is null.

Examples

The following example creates an element with time span content. It then retrieves the value by casting to TimeSpan.

XElement root = new XElement("Root", new TimeSpan(1, 5, 30));
TimeSpan value = (TimeSpan)root;
Console.WriteLine("value={0}", value);
Dim root As XElement = <Root><%= New TimeSpan(1, 5, 30) %></Root>
Dim value As TimeSpan = CType(root, TimeSpan)
Console.WriteLine("value={0}", value)

This example produces the following output:

value=01:05:30

Remarks

The value space of an attribute or element that contains time span content is closely related to duration content as described in ISO 8601. When creating an attribute or element that contains time span content, the attribute or element values are formatted per the W3C specification. Please see the W3C specification for more details.

Behavior is lax when casting to a TimeSpan from an attribute or element. Even if the attribute or element value is not formatted exactly per the W3C specification, the value is appropriately converted to a TimeSpan.

See also

Applies to

Explicit(XElement to UInt64)

Source:
XElement.cs
Source:
XElement.cs
Source:
XElement.cs

Important

This API is not CLS-compliant.

Cast the value of this XElement to a UInt64.

public:
 static explicit operator System::UInt64(System::Xml::Linq::XElement ^ element);
[System.CLSCompliant(false)]
public static explicit operator ulong (System.Xml.Linq.XElement element);
[<System.CLSCompliant(false)>]
static member op_Explicit : System.Xml.Linq.XElement -> uint64
Public Shared Narrowing Operator CType (element As XElement) As ULong

Parameters

element
XElement

The XElement to cast to UInt64.

Returns

A UInt64 that contains the content of this XElement.

Attributes

Exceptions

The element does not contain a valid UInt64 value.

The element parameter is null.

element is null.

Examples

The following example creates an element with unsigned long integer content. It then retrieves the value by casting to UInt64.

XElement root = new XElement("Root", 18446744073709551615);
ulong value = (ulong)root;
Console.WriteLine("value={0}", value);
Dim root As XElement = <Root>18446744073709551615</Root>
Dim value As ULong = CULng(root)
Console.WriteLine("value={0}", value)

This example produces the following output:

value=18446744073709551615

See also

Applies to

Explicit(XElement to Nullable<Int32>)

Source:
XElement.cs
Source:
XElement.cs
Source:
XElement.cs

Important

This API is not CLS-compliant.

Cast the value of this XElement to a Nullable<T> of Int32.

public:
 static explicit operator Nullable<int>(System::Xml::Linq::XElement ^ element);
[System.CLSCompliant(false)]
public static explicit operator int? (System.Xml.Linq.XElement element);
[System.CLSCompliant(false)]
public static explicit operator int? (System.Xml.Linq.XElement? element);
[<System.CLSCompliant(false)>]
static member op_Explicit : System.Xml.Linq.XElement -> Nullable<int>
Public Shared Narrowing Operator CType (element As XElement) As Nullable(Of Integer)

Parameters

element
XElement

The XElement to cast to Nullable<T> of Int32.

Returns

A Nullable<T> of Int32 that contains the content of this XElement.

Attributes

Exceptions

The element is not null and does not contain a valid Int32 value.

Examples

The following example creates an element with unsigned integer content. It then retrieves the value by casting to Nullable<T> of Int32.

XElement root = new XElement("Root",
    new XElement("Value", 2147483647)
);
int? value = (int?)root.Element("Value");
Console.WriteLine("Nullable integer: value={0}", value == null ? "null" : value.ToString());
Dim root As XElement = _
        <Root>
            <Value>2147483647</Value>
        </Root>
Dim value As Nullable(Of Integer) = CType(root.Element("Value"), Nullable(Of Integer))
Console.WriteLine("Nullable integer: value={0}", IIf(value.HasValue, value.ToString(), "null"))

This example produces the following output:

Nullable integer: value=2147483647

See also

Applies to

Explicit(XElement to Single)

Source:
XElement.cs
Source:
XElement.cs
Source:
XElement.cs

Important

This API is not CLS-compliant.

Cast the value of this XElement to a Single.

public:
 static explicit operator float(System::Xml::Linq::XElement ^ element);
[System.CLSCompliant(false)]
public static explicit operator float (System.Xml.Linq.XElement element);
[<System.CLSCompliant(false)>]
static member op_Explicit : System.Xml.Linq.XElement -> single
Public Shared Narrowing Operator CType (element As XElement) As Single

Parameters

element
XElement

The XElement to cast to Single.

Returns

A Single that contains the content of this XElement.

Attributes

Exceptions

The element does not contain a valid Single value.

The element parameter is null.

element is null.

Examples

The following example creates an element with single precision floating point content. It then retrieves the value by casting to Single.

XElement root = new XElement("Root", 3.402823e38);
float value = (float)root;
Console.WriteLine("value={0}", value);
Dim root As XElement = <Root>3.402823E+38</Root>
Dim value As Single = CSng(root)
Console.WriteLine("value={0}", value)

This example produces the following output:

value=3.402823E+38

See also

Applies to

Explicit(XElement to Nullable<Guid>)

Source:
XElement.cs
Source:
XElement.cs
Source:
XElement.cs

Important

This API is not CLS-compliant.

Cast the value of this XElement to a Nullable<T> of Guid.

public:
 static explicit operator Nullable<Guid>(System::Xml::Linq::XElement ^ element);
[System.CLSCompliant(false)]
public static explicit operator Guid? (System.Xml.Linq.XElement element);
[System.CLSCompliant(false)]
public static explicit operator Guid? (System.Xml.Linq.XElement? element);
[<System.CLSCompliant(false)>]
static member op_Explicit : System.Xml.Linq.XElement -> Nullable<Guid>
Public Shared Narrowing Operator CType (element As XElement) As Nullable(Of Guid)

Parameters

element
XElement

The XElement to cast to Nullable<T> of Guid.

Returns

A Nullable<T> of Guid that contains the content of this XElement.

Attributes

Exceptions

The element is not null and does not contain a valid Guid value.

Examples

The following example creates an element with guid content. It then retrieves the value by casting to Nullable<T> of Guid.

XElement root = new XElement("Root",
    new XElement("Value", new Guid("3c1cc55b-baff-4b7a-9d17-077af3aa5730"))
);
Guid? value = (Guid?)root.Element("Value");
Console.WriteLine("Nullable Guid: value={0}", value == null ? "null" : value.ToString());
Dim root As XElement = _
    <Root>
        <Value><%= New Guid("3c1cc55b-baff-4b7a-9d17-077af3aa5730") %></Value>
    </Root>
Dim value As Nullable(Of Guid) = CType(root.Element("Value"), Nullable(Of Guid))
Console.WriteLine("Nullable Guid: value={0}", IIf(value.HasValue, value.ToString(), "null"))

This example produces the following output:

Nullable Guid: value=3c1cc55b-baff-4b7a-9d17-077af3aa5730

See also

Applies to

Explicit(XElement to Nullable<Boolean>)

Source:
XElement.cs
Source:
XElement.cs
Source:
XElement.cs

Important

This API is not CLS-compliant.

Cast the value of this XElement to a Nullable<T> of Boolean.

public:
 static explicit operator Nullable<bool>(System::Xml::Linq::XElement ^ element);
[System.CLSCompliant(false)]
public static explicit operator bool? (System.Xml.Linq.XElement element);
[System.CLSCompliant(false)]
public static explicit operator bool? (System.Xml.Linq.XElement? element);
[<System.CLSCompliant(false)>]
static member op_Explicit : System.Xml.Linq.XElement -> Nullable<bool>
Public Shared Narrowing Operator CType (element As XElement) As Nullable(Of Boolean)

Parameters

element
XElement

The XElement to cast to Nullable<T> of Boolean.

Returns

A Nullable<T> of Boolean that contains the content of this XElement.

Attributes

Exceptions

The element is not null and does not contain a valid Boolean value.

Examples

The following example creates an element with boolean content. It then retrieves the value by casting to Nullable<T> of Boolean.

XElement root = new XElement("Root",
    new XElement("BoolValue1", true),
    new XElement("BoolValue2", false));
bool? bool1 = (bool?)root.Element("BoolValue1");
bool? bool2 = (bool?)root.Element("BoolValue2");
Console.WriteLine("Nullable Boolean: value1={0}", bool1);
Console.WriteLine("Nullable Boolean: value2={0}", bool2);
Dim root As XElement = _
        <Root>
            <BoolValue1>true</BoolValue1>
            <BoolValue2>false</BoolValue2>
        </Root>

Dim value1 As Nullable(Of Boolean) = CType(root.Element("BoolValue1"), Nullable(Of Boolean))
Dim value2 As Nullable(Of Boolean) = CType(root.Element("BoolValue2"), Nullable(Of Boolean))
Console.WriteLine("Nullable Boolean: value1={0}", IIf(value1.HasValue, value1.ToString(), "null"))
Console.WriteLine("Nullable Boolean: value2={0}", IIf(value2.HasValue, value2.ToString(), "null"))

This example produces the following output:

Nullable Boolean: value1=True
Nullable Boolean: value2=False

Remarks

When converting to Nullable<T> of Boolean from an attribute or element, allowed values are "0", "1", and any string that produces "true" or "false" after trimming and conversion to lower case.

See also

Applies to

Explicit(XElement to Nullable<Decimal>)

Source:
XElement.cs
Source:
XElement.cs
Source:
XElement.cs

Important

This API is not CLS-compliant.

Cast the value of this XElement to a Nullable<T> of Decimal.

public:
 static explicit operator Nullable<System::Decimal>(System::Xml::Linq::XElement ^ element);
[System.CLSCompliant(false)]
public static explicit operator decimal? (System.Xml.Linq.XElement element);
[System.CLSCompliant(false)]
public static explicit operator decimal? (System.Xml.Linq.XElement? element);
[<System.CLSCompliant(false)>]
static member op_Explicit : System.Xml.Linq.XElement -> Nullable<decimal>
Public Shared Narrowing Operator CType (element As XElement) As Nullable(Of Decimal)

Parameters

element
XElement

The XElement to cast to Nullable<T> of Decimal.

Returns

A Nullable<T> of Decimal that contains the content of this XElement.

Attributes

Exceptions

The element is not null and does not contain a valid Decimal value.

Examples

The following example creates an element with decimal content. It then retrieves the value by casting to Nullable<T> of Decimal.

XElement root = new XElement("Root",
    new XElement("Value", "79228162514264337593543950335")
);
decimal? value = (decimal?)root.Element("Value");
Console.WriteLine("Nullable decimal: value={0}", value == null ? "null" : value.ToString());
Dim root As XElement = _
    <Root>
        <Value>79228162514264337593543950335</Value>
    </Root>
Dim value As Nullable(Of Decimal) = CType(root.Element("Value"), Nullable(Of Decimal))
Console.WriteLine("Nullable decimal: value={0}", IIf(value.HasValue, value.ToString(), "null"))

This example produces the following output:

Nullable decimal: value=79228162514264337593543950335

See also

Applies to

Explicit(XElement to Boolean)

Source:
XElement.cs
Source:
XElement.cs
Source:
XElement.cs

Important

This API is not CLS-compliant.

Cast the value of this XElement to a Boolean.

public:
 static explicit operator bool(System::Xml::Linq::XElement ^ element);
[System.CLSCompliant(false)]
public static explicit operator bool (System.Xml.Linq.XElement element);
[<System.CLSCompliant(false)>]
static member op_Explicit : System.Xml.Linq.XElement -> bool
Public Shared Narrowing Operator CType (element As XElement) As Boolean

Parameters

element
XElement

The XElement to cast to Boolean.

Returns

A Boolean that contains the content of this XElement.

Attributes

Exceptions

The element does not contain a valid Boolean value.

The element parameter is null.

Examples

The following example creates some elements with boolean values. It then casts them to Boolean.

XElement root = new XElement("Root",
    new XElement("BoolValue1", true),
    new XElement("BoolValue2", false)
);
bool bool1 = (bool)root.Element("BoolValue1");
bool bool2 = (bool)root.Element("BoolValue2");
Console.WriteLine("(bool)BoolValue1={0}", bool1);
Console.WriteLine("(bool)BoolValue2={0}", bool2);
Dim root As XElement = _
        <Root>
            <BoolValue1>true</BoolValue1>
            <BoolValue2>false</BoolValue2>
        </Root>
Dim bool1 As Boolean = CBool(root.Element("BoolValue1"))
Dim bool2 As Boolean = CBool(root.Element("BoolValue2"))
Console.WriteLine("(bool)BoolValue1={0}", bool1)
Console.WriteLine("(bool)BoolValue2={0}", bool2)

This example produces the following output:

(bool)BoolValue1=True
(bool)BoolValue2=False

Remarks

When converting to Boolean from an attribute or element, allowed values are "0", "1", and any string that produces "true" or "false" after trimming and conversion to lower case.

See also

Applies to

Explicit(XElement to DateTime)

Source:
XElement.cs
Source:
XElement.cs
Source:
XElement.cs

Important

This API is not CLS-compliant.

Cast the value of this XElement to a DateTime.

public:
 static explicit operator DateTime(System::Xml::Linq::XElement ^ element);
[System.CLSCompliant(false)]
public static explicit operator DateTime (System.Xml.Linq.XElement element);
[<System.CLSCompliant(false)>]
static member op_Explicit : System.Xml.Linq.XElement -> DateTime
Public Shared Narrowing Operator CType (element As XElement) As DateTime

Parameters

element
XElement

The XElement to cast to DateTime.

Returns

A DateTime that contains the content of this XElement.

Attributes

Exceptions

The element does not contain a valid DateTime value.

The element parameter is null.

element is null.

Examples

The following example creates an element with date and time content. It then casts it to DateTime to retrieve the value.

// Behavior is strict when formatting an XML element or attribute from a DateTime,
// but behavior is lax when casting to a DateTime from an element or attribute.
XElement root = new XElement("Root", new DateTime(2006, 10, 6, 12, 30, 0));
Console.WriteLine(root);

// Cast from a strictly formatted XML element.
DateTime dt = (DateTime)root;
Console.WriteLine("dt={0}", dt);
Console.WriteLine("-----");

// If root is formatted in some different way:
XElement dtElement = new XElement("OrderDate", "October 6, 2006");
Console.WriteLine(dtElement);
DateTime orderDate = (DateTime)dtElement;
Console.WriteLine("orderDate={0:d}", orderDate);
' Behavior is strict when formatting an XML element or attribute from a DateTime,
' but behavior is lax when casting to a DateTime from an element or attribute.
Dim root As XElement = <Root><%= New DateTime(2006, 10, 6, 12, 30, 0) %></Root>
Console.WriteLine(root)

' Cast from a strictly formatted XML element.
Dim dt As DateTime = CType(root, DateTime)
Console.WriteLine("dt={0}", dt)
Console.WriteLine("-----")

' If root is formatted in some different way:
Dim dtElement As XElement = <OrderDate>October 6, 2006</OrderDate>
Console.WriteLine(dtElement)
Dim orderDate As DateTime = CType(dtElement, DateTime)
Console.WriteLine("orderDate={0:d}", orderDate)

This example produces the following output:

<Root>2006-10-06T12:30:00</Root>
dt=10/6/2006 12:30:00 PM
-----
<OrderDate>October 6, 2006</OrderDate>
orderDate=10/6/2006

Remarks

The value space of an attribute or element that contains date and time content is closely related to the dates and times described in ISO 8601. When creating an attribute or element that contains date and time content, the attribute or element values are formatted per the W3C specification. See the W3C specification for more details.

Behavior is lax when casting to a DateTime from an attribute or element. Even if the attribute or element value is not formatted exactly per the W3C specification, the value is appropriately converted to a DateTime.

This conversion operator uses CultureInfo.InvariantCulture to convert from a DateTime.

See also

Applies to

Explicit(XElement to DateTimeOffset)

Source:
XElement.cs
Source:
XElement.cs
Source:
XElement.cs

Important

This API is not CLS-compliant.

Cast the value of this XAttribute to a DateTimeOffset.

public:
 static explicit operator DateTimeOffset(System::Xml::Linq::XElement ^ element);
[System.CLSCompliant(false)]
public static explicit operator DateTimeOffset (System.Xml.Linq.XElement element);
[<System.CLSCompliant(false)>]
static member op_Explicit : System.Xml.Linq.XElement -> DateTimeOffset
Public Shared Narrowing Operator CType (element As XElement) As DateTimeOffset

Parameters

element
XElement

The XElement to cast to DateTimeOffset.

Returns

A DateTimeOffset that contains the content of this XElement.

Attributes

Exceptions

The element does not contain a valid DateTimeOffset value.

The element parameter is null.

element is null.

Examples

The following example creates an element with date and time content. It then casts to DateTimeOffset to retrieve the value.

XElement root = new XElement("Root",
    new XElement("Child", new DateTimeOffset(new DateTime(2006, 10, 6, 12, 30, 0)))
);
Console.WriteLine(root);

DateTimeOffset dt = (DateTimeOffset)root.Element("Child");
Console.WriteLine("dt={0}", dt);
Dim root As XElement = _
    <Root>
        <Child><%= New DateTimeOffset(New DateTime(2006, 10, 6, 12, 30, 0)) %></Child>
    </Root>
Console.WriteLine(root)

Dim dt As DateTimeOffset = CType(root.<Child>(0), DateTimeOffset)
Console.WriteLine("dt={0}", dt)

This example produces the following output:

<Root>
  <Child>2006-10-06T12:30:00-07:00</Child>
</Root>
dt=10/6/2006 12:30:00 PM -07:00

Remarks

This conversion operator uses the XmlConvert class to do the conversion.

See also

Applies to

Explicit(XElement to Double)

Source:
XElement.cs
Source:
XElement.cs
Source:
XElement.cs

Important

This API is not CLS-compliant.

Cast the value of this XElement to a Double.

public:
 static explicit operator double(System::Xml::Linq::XElement ^ element);
[System.CLSCompliant(false)]
public static explicit operator double (System.Xml.Linq.XElement element);
[<System.CLSCompliant(false)>]
static member op_Explicit : System.Xml.Linq.XElement -> double
Public Shared Narrowing Operator CType (element As XElement) As Double

Parameters

element
XElement

The XElement to cast to Double.

Returns

A Double that contains the content of this XElement.

Attributes

Exceptions

The element does not contain a valid Double value.

The element parameter is null.

element is null.

Examples

The following example creates an attribute with double content. It then retrieves the value by casting to Double.

XElement root = new XElement("Root", 1.79769313486231e308);
double value = (double)root;
Console.WriteLine("value={0}", value);
Dim root As XElement = <Root>1.79769313486231E+308</Root>
Dim value As Double = CDbl(root)
Console.WriteLine("value={0}", value)

This example produces the following output:

value=1.79769313486231E+308

See also

Applies to

Explicit(XElement to Guid)

Source:
XElement.cs
Source:
XElement.cs
Source:
XElement.cs

Important

This API is not CLS-compliant.

Cast the value of this XElement to a Guid.

public:
 static explicit operator Guid(System::Xml::Linq::XElement ^ element);
[System.CLSCompliant(false)]
public static explicit operator Guid (System.Xml.Linq.XElement element);
[<System.CLSCompliant(false)>]
static member op_Explicit : System.Xml.Linq.XElement -> Guid
Public Shared Narrowing Operator CType (element As XElement) As Guid

Parameters

element
XElement

The XElement to cast to Guid.

Returns

A Guid that contains the content of this XElement.

Attributes

Exceptions

The element does not contain a valid Guid value.

The element parameter is null.

element is null.

Examples

The following example creates an element with a guid as content. It then retrieves the value by casting to Guid.

XElement root = new XElement("Root", new Guid("3c1cc55b-baff-4b7a-9d17-077af3aa5730"));
Guid value = (Guid)root;
Console.WriteLine("value={0}", value);
Dim root As XElement = <Root><%= New Guid("3c1cc55b-baff-4b7a-9d17-077af3aa5730") %></Root>
Dim value As Guid = CType(root, Guid)
Console.WriteLine("value={0}", value)

This example produces the following output:

value=3c1cc55b-baff-4b7a-9d17-077af3aa5730

See also

Applies to

Explicit(XElement to Decimal)

Source:
XElement.cs
Source:
XElement.cs
Source:
XElement.cs

Important

This API is not CLS-compliant.

Cast the value of this XElement to a Decimal.

public:
 static explicit operator System::Decimal(System::Xml::Linq::XElement ^ element);
[System.CLSCompliant(false)]
public static explicit operator decimal (System.Xml.Linq.XElement element);
[<System.CLSCompliant(false)>]
static member op_Explicit : System.Xml.Linq.XElement -> decimal
Public Shared Narrowing Operator CType (element As XElement) As Decimal

Parameters

element
XElement

The XElement to cast to Decimal.

Returns

A Decimal that contains the content of this XElement.

Attributes

Exceptions

The element does not contain a valid Decimal value.

The element parameter is null.

element is null.

Examples

The following example creates an element with a decimal value. It then retrieves the value of the attribute by casting to Decimal.

XElement root = new XElement("Root", "79228162514264337593543950335");
decimal value = (decimal)root;
Console.WriteLine("value={0}", value);
Dim root As XElement = <Root>79228162514264337593543950335</Root>
Dim value As Decimal = CDec(root)
Console.WriteLine("value={0}", value)

This example produces the following output:

value=79228162514264337593543950335

See also

Applies to

Explicit(XElement to Int64)

Source:
XElement.cs
Source:
XElement.cs
Source:
XElement.cs

Important

This API is not CLS-compliant.

Cast the value of this XElement to an Int64.

public:
 static explicit operator long(System::Xml::Linq::XElement ^ element);
[System.CLSCompliant(false)]
public static explicit operator long (System.Xml.Linq.XElement element);
[<System.CLSCompliant(false)>]
static member op_Explicit : System.Xml.Linq.XElement -> int64
Public Shared Narrowing Operator CType (element As XElement) As Long

Parameters

element
XElement

The XElement to cast to Int64.

Returns

A Int64 that contains the content of this XElement.

Attributes

Exceptions

The element does not contain a valid Int64 value.

The element parameter is null.

element is null.

Examples

The following example creates an element with a long integer as content. It then retrieves the value of the element by casting to Int64.

XElement root = new XElement("Root", 9223372036854775807);
long value = (long)root;
Console.WriteLine("value={0}", value);
Dim root As XElement = <Root>9223372036854775807</Root>
Dim value As Long = CLng(root)
Console.WriteLine("value={0}", value)

This example produces the following output:

value=9223372036854775807

See also

Applies to

Explicit(XElement to Nullable<Double>)

Source:
XElement.cs
Source:
XElement.cs
Source:
XElement.cs

Important

This API is not CLS-compliant.

Cast the value of this XElement to a Nullable<T> of Double.

public:
 static explicit operator Nullable<double>(System::Xml::Linq::XElement ^ element);
[System.CLSCompliant(false)]
public static explicit operator double? (System.Xml.Linq.XElement element);
[System.CLSCompliant(false)]
public static explicit operator double? (System.Xml.Linq.XElement? element);
[<System.CLSCompliant(false)>]
static member op_Explicit : System.Xml.Linq.XElement -> Nullable<double>
Public Shared Narrowing Operator CType (element As XElement) As Nullable(Of Double)

Parameters

element
XElement

The XElement to cast to Nullable<T> of Double.

Returns

A Nullable<T> of Double that contains the content of this XElement.

Attributes

Exceptions

The element is not null and does not contain a valid Double value.

Examples

The following example creates an element with double precision floating point content. It then retrieves the value by casting to Nullable<T> of Double.

XElement root = new XElement("Root",
    new XElement("Value", 1.79769313486231e308)
);
double? value = (double?)root.Element("Value");
Console.WriteLine("Nullable double: value={0}", value == null ? "null" : value.ToString());
Dim root As XElement = _
        <Root>
            <Value>1.79769313486231e308</Value>
        </Root>

Dim value As Nullable(Of Double) = CType(root.Element("Value"), Nullable(Of Double))
Console.WriteLine("Nullable double: value={0}", IIf(value.HasValue, value.ToString(), "null"))

This example produces the following output:

Nullable double: value=1.79769313486231E+308

See also

Applies to

Explicit(XElement to Nullable<DateTime>)

Source:
XElement.cs
Source:
XElement.cs
Source:
XElement.cs

Important

This API is not CLS-compliant.

Cast the value of this XElement to a Nullable<T> of DateTime.

public:
 static explicit operator Nullable<DateTime>(System::Xml::Linq::XElement ^ element);
[System.CLSCompliant(false)]
public static explicit operator DateTime? (System.Xml.Linq.XElement element);
[System.CLSCompliant(false)]
public static explicit operator DateTime? (System.Xml.Linq.XElement? element);
[<System.CLSCompliant(false)>]
static member op_Explicit : System.Xml.Linq.XElement -> Nullable<DateTime>
Public Shared Narrowing Operator CType (element As XElement) As Nullable(Of DateTime)

Parameters

element
XElement

The XElement to cast to Nullable<T> of DateTime.

Returns

A Nullable<T> of DateTime that contains the content of this XElement.

Attributes

Exceptions

The element is not null and does not contain a valid DateTime value.

Examples

The following example creates an element with a date and time as content. It then retrieves the value by casting to Nullable<T> of DateTime.

XElement root = new XElement("Root",
    new XElement("Value", new DateTime(2006, 10, 6, 12, 30, 0))
);
DateTime? value = (DateTime?)root.Element("Value");
Console.WriteLine("Nullable DateTime: value={0}", value == null ? "null" : value.ToString());
Dim root As XElement = _
    <Root>
        <Value><%= New DateTime(2006, 10, 6, 12, 30, 0) %></Value>
    </Root>
Dim value As Nullable(Of DateTime) = CType(root.Element("Value"), Nullable(Of DateTime))
Console.WriteLine("Nullable DateTime: value={0}", IIf(value.HasValue, value.ToString(), "null"))

This example produces the following output:

Nullable DateTime: value=10/6/2006 12:30:00 PM

Remarks

The value space of an attribute or element that contains date and time content is closely related to the dates and times described in ISO 8601. When creating an attribute or element that contains date and time content, the attribute or element values are formatted per the W3C specification. See the W3C specification for more details.

The behavior is lax when casting to a Nullable<T> of DateTime from an attribute or element. Even if the attribute or element value is not formatted exactly per the W3C specification, the value is appropriately converted to a Nullable<T> of DateTime.

This conversion operator uses CultureInfo.InvariantCulture to convert from a DateTime.

See also

Applies to

Explicit(XElement to Nullable<DateTimeOffset>)

Source:
XElement.cs
Source:
XElement.cs
Source:
XElement.cs

Important

This API is not CLS-compliant.

Cast the value of this XElement to a Nullable<T> of DateTimeOffset.

public:
 static explicit operator Nullable<DateTimeOffset>(System::Xml::Linq::XElement ^ element);
[System.CLSCompliant(false)]
public static explicit operator DateTimeOffset? (System.Xml.Linq.XElement element);
[System.CLSCompliant(false)]
public static explicit operator DateTimeOffset? (System.Xml.Linq.XElement? element);
[<System.CLSCompliant(false)>]
static member op_Explicit : System.Xml.Linq.XElement -> Nullable<DateTimeOffset>
Public Shared Narrowing Operator CType (element As XElement) As Nullable(Of DateTimeOffset)

Parameters

element
XElement

The XElement to cast to an Nullable<T> of DateTimeOffset.

Returns

A Nullable<T> of DateTimeOffset that contains the content of this XElement.

Attributes

Exceptions

The element is not null and does not contain a valid DateTimeOffset value.

Examples

The following example creates an element with date and time content. It then casts to Nullable<T> of DateTimeOffset to retrieve the value.

XElement root = new XElement("Root",
    new XElement("Child", new DateTimeOffset(new DateTime(2006, 10, 6, 12, 30, 0)))
);
Console.WriteLine(root);

DateTimeOffset? dt = (DateTimeOffset?)root.Element("Child");
Console.WriteLine("dt={0}", dt);
Dim root As XElement = _
    <Root>
        <Child><%= New DateTimeOffset(New DateTime(2006, 10, 6, 12, 30, 0)) %></Child>
    </Root>
Console.WriteLine(root)

Dim dt As Nullable(Of DateTimeOffset) = CType(root.<Child>(0), Nullable(Of DateTimeOffset))
Console.WriteLine("dt={0}", dt)

This example produces the following output:

<Root>
  <Child>2006-10-06T12:30:00-07:00</Child>
</Root>
dt=10/6/2006 12:30:00 PM -07:00

Remarks

This conversion operator uses the XmlConvert class to do the conversion.

See also

Applies to

Explicit(XElement to Int32)

Source:
XElement.cs
Source:
XElement.cs
Source:
XElement.cs

Important

This API is not CLS-compliant.

Cast the value of this XElement to an Int32.

public:
 static explicit operator int(System::Xml::Linq::XElement ^ element);
[System.CLSCompliant(false)]
public static explicit operator int (System.Xml.Linq.XElement element);
[<System.CLSCompliant(false)>]
static member op_Explicit : System.Xml.Linq.XElement -> int
Public Shared Narrowing Operator CType (element As XElement) As Integer

Parameters

element
XElement

The XElement to cast to Int32.

Returns

A Int32 that contains the content of this XElement.

Attributes

Exceptions

The element does not contain a valid Int32 value.

The element parameter is null.

Examples

The following example creates an element with an integer as content. It then retrieves the value by casting to Int32.

XElement root = new XElement("Root", 2147483647);
int value = (int)root;
Console.WriteLine("value={0}", value);
Dim root As XElement = <Root>2147483647</Root>
Dim value As Integer = CInt(root)
Console.WriteLine("value={0}", value)

This example produces the following output:

value=2147483647

See also

Applies to