XAttribute.Explicit Operator

Definition

Overloads

Explicit(XAttribute to Nullable<Int64>)

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

Explicit(XAttribute to Nullable<Single>)

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

Explicit(XAttribute to Nullable<TimeSpan>)

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

Explicit(XAttribute to Nullable<UInt32>)

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

Explicit(XAttribute to Nullable<UInt64>)

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

Explicit(XAttribute to TimeSpan)

Cast the value of this XAttribute to a TimeSpan.

Explicit(XAttribute to String)

Cast the value of this XAttribute to a String.

Explicit(XAttribute to Nullable<Int32>)

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

Explicit(XAttribute to UInt32)

Cast the value of this XAttribute to a UInt32.

Explicit(XAttribute to UInt64)

Cast the value of this XAttribute to a UInt64.

Explicit(XAttribute to Single)

Cast the value of this XAttribute to a Single.

Explicit(XAttribute to Nullable<Guid>)

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

Explicit(XAttribute to Nullable<Decimal>)

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

Explicit(XAttribute to Decimal)

Cast the value of this XAttribute to a Decimal.

Explicit(XAttribute to Nullable<DateTimeOffset>)

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

Explicit(XAttribute to Nullable<DateTime>)

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

Explicit(XAttribute to Nullable<Boolean>)

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

Explicit(XAttribute to Int64)

Cast the value of this XAttribute to an Int64.

Explicit(XAttribute to Int32)

Cast the value of this XAttribute to an Int32.

Explicit(XAttribute to Guid)

Cast the value of this XAttribute to a Guid.

Explicit(XAttribute to Double)

Cast the value of this XAttribute to a Double.

Explicit(XAttribute to Nullable<Double>)

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

Explicit(XAttribute to DateTimeOffset)

Cast the value of this XAttribute to a DateTimeOffset.

Explicit(XAttribute to DateTime)

Cast the value of this XAttribute to a DateTime.

Explicit(XAttribute to Boolean)

Cast the value of this XAttribute to a Boolean.

Explicit(XAttribute to Nullable<Int64>)

Source:
XAttribute.cs
Source:
XAttribute.cs
Source:
XAttribute.cs

Important

This API is not CLS-compliant.

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

C#
[System.CLSCompliant(false)]
public static explicit operator long?(System.Xml.Linq.XAttribute attribute);
C#
[System.CLSCompliant(false)]
public static explicit operator long?(System.Xml.Linq.XAttribute? attribute);

Parameters

attribute
XAttribute

The XAttribute to cast to a Nullable<T> of Int64.

Returns

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

Attributes

Exceptions

The attribute does not contain a valid Int64 value.

Examples

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

C#
XElement root = new XElement("Root",   
    new XAttribute("Att", 9223372036854775807)  
);  
long? value = (long?)root.Attribute("Att");  
Console.WriteLine("Nullable long: value={0}", value == null ? "null" : value.ToString());  

This example produces the following output:

Nullable long: value=9223372036854775807  

See also

Applies to

.NET 10 i druge verzije
Proizvod Verzije
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

Explicit(XAttribute to Nullable<Single>)

Source:
XAttribute.cs
Source:
XAttribute.cs
Source:
XAttribute.cs

Important

This API is not CLS-compliant.

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

C#
[System.CLSCompliant(false)]
public static explicit operator float?(System.Xml.Linq.XAttribute attribute);
C#
[System.CLSCompliant(false)]
public static explicit operator float?(System.Xml.Linq.XAttribute? attribute);

Parameters

attribute
XAttribute

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

Returns

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

Attributes

Exceptions

The attribute does not contain a valid Single value.

Examples

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

C#
XElement root = new XElement("Root",   
    new XAttribute("Att", 3.402823e38)  
);  
float? value = (float?)root.Attribute("Att");  
Console.WriteLine("Nullable Single: value={0}", value == null ? "null" : value.ToString());  

This example produces the following output:

Nullable Single: value=3.402823E+38  

See also

Applies to

.NET 10 i druge verzije
Proizvod Verzije
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

Explicit(XAttribute to Nullable<TimeSpan>)

Source:
XAttribute.cs
Source:
XAttribute.cs
Source:
XAttribute.cs

Important

This API is not CLS-compliant.

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

C#
[System.CLSCompliant(false)]
public static explicit operator TimeSpan?(System.Xml.Linq.XAttribute attribute);
C#
[System.CLSCompliant(false)]
public static explicit operator TimeSpan?(System.Xml.Linq.XAttribute? attribute);

Parameters

attribute
XAttribute

The XAttribute to cast to a Nullable<T> of TimeSpan.

Returns

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

Attributes

Exceptions

The attribute does not contain a valid TimeSpan value.

Examples

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

C#
XElement root = new XElement("Root",  
    new XAttribute("Att", new TimeSpan(1, 5, 30))  
);  
TimeSpan? value = (TimeSpan?)root.Attribute("Att");  
Console.WriteLine("Nullable TimeSpan: value={0}", value == null ? "null" : value.ToString());  

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

.NET 10 i druge verzije
Proizvod Verzije
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

Explicit(XAttribute to Nullable<UInt32>)

Source:
XAttribute.cs
Source:
XAttribute.cs
Source:
XAttribute.cs

Important

This API is not CLS-compliant.

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

C#
[System.CLSCompliant(false)]
public static explicit operator uint?(System.Xml.Linq.XAttribute attribute);
C#
[System.CLSCompliant(false)]
public static explicit operator uint?(System.Xml.Linq.XAttribute? attribute);

Parameters

attribute
XAttribute

The XAttribute to cast to a Nullable<T> of UInt32.

Returns

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

Attributes

Exceptions

The attribute does not contain a valid UInt32 value.

Examples

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

C#
XElement root = new XElement("Root",   
    new XAttribute("Att", 4294967295)  
);  
uint? value = (uint?)root.Attribute("Att");  
Console.WriteLine("Nullable uint: value={0}", value == null ? "null" : value.ToString());  

This example produces the following output:

Nullable uint: value=4294967295  

See also

Applies to

.NET 10 i druge verzije
Proizvod Verzije
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

Explicit(XAttribute to Nullable<UInt64>)

Source:
XAttribute.cs
Source:
XAttribute.cs
Source:
XAttribute.cs

Important

This API is not CLS-compliant.

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

C#
[System.CLSCompliant(false)]
public static explicit operator ulong?(System.Xml.Linq.XAttribute attribute);
C#
[System.CLSCompliant(false)]
public static explicit operator ulong?(System.Xml.Linq.XAttribute? attribute);

Parameters

attribute
XAttribute

The XAttribute to cast to a Nullable<T> of UInt64.

Returns

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

Attributes

Exceptions

The attribute does not contain a valid UInt64 value.

Examples

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

C#
XElement root = new XElement("Root",   
    new XAttribute("Att", 9223372036854775807)  
);  
ulong? value = (ulong?)root.Attribute("Att");  
Console.WriteLine("Nullable ulong: value={0}", value == null ? "null" : value.ToString());  

This example produces the following output:

Nullable ulong: value=9223372036854775807  

See also

Applies to

.NET 10 i druge verzije
Proizvod Verzije
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

Explicit(XAttribute to TimeSpan)

Source:
XAttribute.cs
Source:
XAttribute.cs
Source:
XAttribute.cs

Important

This API is not CLS-compliant.

Cast the value of this XAttribute to a TimeSpan.

C#
[System.CLSCompliant(false)]
public static explicit operator TimeSpan(System.Xml.Linq.XAttribute attribute);

Parameters

attribute
XAttribute

The XAttribute to cast to TimeSpan.

Returns

A TimeSpan that contains the content of this XAttribute.

Attributes

Exceptions

The attribute does not contain a valid TimeSpan value.

The attribute parameter is null.

Examples

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

C#
XElement root = new XElement("Root",  
    new XAttribute("Att", new TimeSpan(1, 5, 30))  
);  
TimeSpan value = (TimeSpan)root.Attribute("Att");  
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

.NET 10 i druge verzije
Proizvod Verzije
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

Explicit(XAttribute to String)

Source:
XAttribute.cs
Source:
XAttribute.cs
Source:
XAttribute.cs

Important

This API is not CLS-compliant.

Cast the value of this XAttribute to a String.

C#
[System.CLSCompliant(false)]
public static explicit operator string(System.Xml.Linq.XAttribute attribute);
C#
[System.CLSCompliant(false)]
public static explicit operator string?(System.Xml.Linq.XAttribute? attribute);

Parameters

attribute
XAttribute

The XAttribute to cast to String.

Returns

A String that contains the content of this XAttribute.

Attributes

Examples

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

C#
XElement root = new XElement("Root",  
    new XAttribute("Att", "attribute content")  
);  
XAttribute att = root.Attribute("Att");  
string str = (string)att;  
Console.WriteLine("(string)att={0}", str);  

This example produces the following output:

(string)att=attribute content  

See also

Applies to

.NET 10 i druge verzije
Proizvod Verzije
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

Explicit(XAttribute to Nullable<Int32>)

Source:
XAttribute.cs
Source:
XAttribute.cs
Source:
XAttribute.cs

Important

This API is not CLS-compliant.

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

C#
[System.CLSCompliant(false)]
public static explicit operator int?(System.Xml.Linq.XAttribute attribute);
C#
[System.CLSCompliant(false)]
public static explicit operator int?(System.Xml.Linq.XAttribute? attribute);

Parameters

attribute
XAttribute

The XAttribute to cast to a Nullable<T> of Int32.

Returns

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

Attributes

Examples

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

C#
XElement root = new XElement("Root",   
    new XAttribute("Att", 2147483647)  
);  
int? value = (int?)root.Attribute("Att");  
Console.WriteLine("Nullable int: value={0}", value == null ? "null" : value.ToString());  

This example produces the following output:

Nullable int: value=2147483647  

See also

Applies to

.NET 10 i druge verzije
Proizvod Verzije
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

Explicit(XAttribute to UInt32)

Source:
XAttribute.cs
Source:
XAttribute.cs
Source:
XAttribute.cs

Important

This API is not CLS-compliant.

Cast the value of this XAttribute to a UInt32.

C#
[System.CLSCompliant(false)]
public static explicit operator uint(System.Xml.Linq.XAttribute attribute);

Parameters

attribute
XAttribute

The XAttribute to cast to UInt32.

Returns

A UInt32 that contains the content of this XAttribute.

Attributes

Exceptions

The attribute does not contain a valid UInt32 value.

The attribute parameter is null.

Examples

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

C#
XElement root = new XElement("Root",   
    new XAttribute("Att", 4294967295)  
);  
uint value = (uint)root.Attribute("Att");  
Console.WriteLine("value={0}", value);  

This example produces the following output:

value=4294967295  

See also

Applies to

.NET 10 i druge verzije
Proizvod Verzije
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

Explicit(XAttribute to UInt64)

Source:
XAttribute.cs
Source:
XAttribute.cs
Source:
XAttribute.cs

Important

This API is not CLS-compliant.

Cast the value of this XAttribute to a UInt64.

C#
[System.CLSCompliant(false)]
public static explicit operator ulong(System.Xml.Linq.XAttribute attribute);

Parameters

attribute
XAttribute

The XAttribute to cast to UInt64.

Returns

A UInt64 that contains the content of this XAttribute.

Attributes

Exceptions

The attribute does not contain a valid UInt64 value.

The attribute parameter is null.

Examples

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

C#
XElement root = new XElement("Root",  
    new XAttribute("Att", 1844674407370955161)  
);  
ulong value = (ulong)root.Attribute("Att");  
Console.WriteLine("value={0}", value);  

This example produces the following output:

value=1844674407370955161  

See also

Applies to

.NET 10 i druge verzije
Proizvod Verzije
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

Explicit(XAttribute to Single)

Source:
XAttribute.cs
Source:
XAttribute.cs
Source:
XAttribute.cs

Important

This API is not CLS-compliant.

Cast the value of this XAttribute to a Single.

C#
[System.CLSCompliant(false)]
public static explicit operator float(System.Xml.Linq.XAttribute attribute);

Parameters

attribute
XAttribute

The XAttribute to cast to Single.

Returns

A Single that contains the content of this XAttribute.

Attributes

Exceptions

The attribute does not contain a valid Single value.

The attribute parameter is null.

Examples

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

C#
XElement root = new XElement("Root",  
    new XAttribute("Att", 3.402823e38)  
);  
float value = (float)root.Attribute("Att");  
Console.WriteLine("value={0}", value);  

This example produces the following output:

value=3.402823E+38  

See also

Applies to

.NET 10 i druge verzije
Proizvod Verzije
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

Explicit(XAttribute to Nullable<Guid>)

Source:
XAttribute.cs
Source:
XAttribute.cs
Source:
XAttribute.cs

Important

This API is not CLS-compliant.

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

C#
[System.CLSCompliant(false)]
public static explicit operator Guid?(System.Xml.Linq.XAttribute attribute);
C#
[System.CLSCompliant(false)]
public static explicit operator Guid?(System.Xml.Linq.XAttribute? attribute);

Parameters

attribute
XAttribute

The XAttribute to cast to a Nullable<T> of Guid.

Returns

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

Attributes

Exceptions

The attribute does not contain a valid Guid value.

Examples

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

C#
XElement root = new XElement("Root",  
    new XAttribute("Att", new Guid("3c1cc55b-baff-4b7a-9d17-077af3aa5730"))  
);  
Guid? value = (Guid?)root.Attribute("Att");  
Console.WriteLine("Nullable Guid: value={0}", value == null ? "null" : value.ToString());  

This example produces the following output:

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

See also

Applies to

.NET 10 i druge verzije
Proizvod Verzije
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

Explicit(XAttribute to Nullable<Decimal>)

Source:
XAttribute.cs
Source:
XAttribute.cs
Source:
XAttribute.cs

Important

This API is not CLS-compliant.

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

C#
[System.CLSCompliant(false)]
public static explicit operator decimal?(System.Xml.Linq.XAttribute attribute);
C#
[System.CLSCompliant(false)]
public static explicit operator decimal?(System.Xml.Linq.XAttribute? attribute);

Parameters

attribute
XAttribute

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

Returns

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

Attributes

Exceptions

The attribute does not contain a valid Decimal value.

Examples

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

C#
XElement root = new XElement("Root",  
    new XAttribute("Att", "79228162514264337593543950335")  
);  
decimal? value = (decimal?)root.Attribute("Att");  
Console.WriteLine("Nullable decimal: value={0}", value == null ? "null" : value.ToString());  

This example produces the following output:

Nullable decimal: value=79228162514264337593543950335  

See also

Applies to

.NET 10 i druge verzije
Proizvod Verzije
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

Explicit(XAttribute to Decimal)

Source:
XAttribute.cs
Source:
XAttribute.cs
Source:
XAttribute.cs

Important

This API is not CLS-compliant.

Cast the value of this XAttribute to a Decimal.

C#
[System.CLSCompliant(false)]
public static explicit operator decimal(System.Xml.Linq.XAttribute attribute);

Parameters

attribute
XAttribute

The XAttribute to cast to Decimal.

Returns

A Decimal that contains the content of this XAttribute.

Attributes

Exceptions

The attribute does not contain a valid Decimal value.

The attribute parameter is null.

Examples

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

C#
XElement root = new XElement("Root",  
    new XAttribute("Att", "79228162514264337593543950335")  
);  
decimal value = (decimal)root.Attribute("Att");  
Console.WriteLine("value={0}", value);  

This example produces the following output:

value=79228162514264337593543950335  

See also

Applies to

.NET 10 i druge verzije
Proizvod Verzije
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

Explicit(XAttribute to Nullable<DateTimeOffset>)

Source:
XAttribute.cs
Source:
XAttribute.cs
Source:
XAttribute.cs

Important

This API is not CLS-compliant.

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

C#
[System.CLSCompliant(false)]
public static explicit operator DateTimeOffset?(System.Xml.Linq.XAttribute attribute);
C#
[System.CLSCompliant(false)]
public static explicit operator DateTimeOffset?(System.Xml.Linq.XAttribute? attribute);

Parameters

attribute
XAttribute

The XAttribute to cast to a Nullable<T> of DateTimeOffset.

Returns

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

Attributes

Exceptions

The attribute does not contain a valid DateTimeOffset value.

Examples

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

C#
XElement root = new XElement("Root",  
    new XAttribute("Att", new DateTimeOffset(new DateTime(2006, 10, 6, 12, 30, 0)))  
);  
DateTimeOffset? value = (DateTimeOffset?)root.Attribute("Att");  
Console.WriteLine("Nullable DateTimeOffset: value={0}", value == null ? "null" : value.ToString());  

This example produces the following output:

Nullable DateTimeOffset: value=10/6/2006 12:30:00 PM -07:00  

Remarks

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

Applies to

.NET 10 i druge verzije
Proizvod Verzije
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

Explicit(XAttribute to Nullable<DateTime>)

Source:
XAttribute.cs
Source:
XAttribute.cs
Source:
XAttribute.cs

Important

This API is not CLS-compliant.

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

C#
[System.CLSCompliant(false)]
public static explicit operator DateTime?(System.Xml.Linq.XAttribute attribute);
C#
[System.CLSCompliant(false)]
public static explicit operator DateTime?(System.Xml.Linq.XAttribute? attribute);

Parameters

attribute
XAttribute

The XAttribute to cast to a Nullable<T> of DateTime.

Returns

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

Attributes

Exceptions

The attribute does not contain a valid DateTime value.

Examples

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

C#
XElement root = new XElement("Root",  
    new XAttribute("Att", new DateTime(2006, 10, 6, 12, 30, 0))  
);  
DateTime? value = (DateTime?)root.Attribute("Att");  
Console.WriteLine("Nullable DateTime: value={0}", value == null ? "null" : value.ToString());  

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.

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

.NET 10 i druge verzije
Proizvod Verzije
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

Explicit(XAttribute to Nullable<Boolean>)

Source:
XAttribute.cs
Source:
XAttribute.cs
Source:
XAttribute.cs

Important

This API is not CLS-compliant.

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

C#
[System.CLSCompliant(false)]
public static explicit operator bool?(System.Xml.Linq.XAttribute attribute);
C#
[System.CLSCompliant(false)]
public static explicit operator bool?(System.Xml.Linq.XAttribute? attribute);

Parameters

attribute
XAttribute

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

Returns

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

Attributes

Exceptions

The attribute does not contain a valid Boolean value.

Examples

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

C#
XElement root = new XElement("Root",   
    new XAttribute("BoolValue1", true),  
    new XAttribute("BoolValue2", false)  
);  
bool? bool1 = (bool?)root.Attribute("BoolValue1");  
bool? bool2 = (bool?)root.Attribute("BoolValue2");  
Console.WriteLine("Nullable boolean: BoolValue1={0}", bool1);  
Console.WriteLine("Nullable boolean: BoolValue2={0}", bool2);  

This example produces the following output:

Nullable boolean: BoolValue1=True  
Nullable boolean: 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

.NET 10 i druge verzije
Proizvod Verzije
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

Explicit(XAttribute to Int64)

Source:
XAttribute.cs
Source:
XAttribute.cs
Source:
XAttribute.cs

Important

This API is not CLS-compliant.

Cast the value of this XAttribute to an Int64.

C#
[System.CLSCompliant(false)]
public static explicit operator long(System.Xml.Linq.XAttribute attribute);

Parameters

attribute
XAttribute

The XAttribute to cast to Int64.

Returns

A Int64 that contains the content of this XAttribute.

Attributes

Exceptions

The attribute does not contain a valid Int64 value.

The attribute parameter is null.

Examples

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

C#
XElement root = new XElement("Root",  
    new XAttribute("Att", 9223372036854775807)  
);  
long value = (long)root.Attribute("Att");  
Console.WriteLine("value={0}", value);  

This example produces the following output:

value=9223372036854775807  

See also

Applies to

.NET 10 i druge verzije
Proizvod Verzije
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

Explicit(XAttribute to Int32)

Source:
XAttribute.cs
Source:
XAttribute.cs
Source:
XAttribute.cs

Important

This API is not CLS-compliant.

Cast the value of this XAttribute to an Int32.

C#
[System.CLSCompliant(false)]
public static explicit operator int(System.Xml.Linq.XAttribute attribute);

Parameters

attribute
XAttribute

The XAttribute to cast to Int32.

Returns

A Int32 that contains the content of this XAttribute.

Attributes

Exceptions

The attribute does not contain a valid Int32 value.

The attribute parameter is null.

Examples

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

C#
XElement root = new XElement("Root",  
    new XAttribute("Att", 2147483647)  
);  
int value = (int)root.Attribute("Att");  
Console.WriteLine("value={0}", value);  

This example produces the following output:

value=2147483647  

See also

Applies to

.NET 10 i druge verzije
Proizvod Verzije
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

Explicit(XAttribute to Guid)

Source:
XAttribute.cs
Source:
XAttribute.cs
Source:
XAttribute.cs

Important

This API is not CLS-compliant.

Cast the value of this XAttribute to a Guid.

C#
[System.CLSCompliant(false)]
public static explicit operator Guid(System.Xml.Linq.XAttribute attribute);

Parameters

attribute
XAttribute

The XAttribute to cast to Guid.

Returns

A Guid that contains the content of this XAttribute.

Attributes

Exceptions

The attribute does not contain a valid Guid value.

The attribute parameter is null.

Examples

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

C#
XElement root = new XElement("Root",  
    new XAttribute("Att", new Guid("3c1cc55b-baff-4b7a-9d17-077af3aa5730"))  
);  
Guid value = (Guid)root.Attribute("Att");  
Console.WriteLine("value={0}", value);  

This example produces the following output:

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

See also

Applies to

.NET 10 i druge verzije
Proizvod Verzije
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

Explicit(XAttribute to Double)

Source:
XAttribute.cs
Source:
XAttribute.cs
Source:
XAttribute.cs

Important

This API is not CLS-compliant.

Cast the value of this XAttribute to a Double.

C#
[System.CLSCompliant(false)]
public static explicit operator double(System.Xml.Linq.XAttribute attribute);

Parameters

attribute
XAttribute

The XAttribute to cast to Double.

Returns

A Double that contains the content of this XAttribute.

Attributes

Exceptions

The attribute does not contain a valid Double value.

The attribute parameter is null.

Examples

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

C#
XElement root = new XElement("Root",  
    new XAttribute("Att", 1.79769313486231e308)  
);  
double value = (double)root.Attribute("Att");  
Console.WriteLine("value={0}", value);  

This example produces the following output:

value=1.79769313486231E+308  

See also

Applies to

.NET 10 i druge verzije
Proizvod Verzije
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

Explicit(XAttribute to Nullable<Double>)

Source:
XAttribute.cs
Source:
XAttribute.cs
Source:
XAttribute.cs

Important

This API is not CLS-compliant.

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

C#
[System.CLSCompliant(false)]
public static explicit operator double?(System.Xml.Linq.XAttribute attribute);
C#
[System.CLSCompliant(false)]
public static explicit operator double?(System.Xml.Linq.XAttribute? attribute);

Parameters

attribute
XAttribute

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

Returns

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

Attributes

Exceptions

The attribute does not contain a valid Double value.

Examples

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

C#
XElement root = new XElement("Root",  
    new XAttribute("Att", 1.79769313486231e308)  
);  
double? value = (double?)root.Attribute("Att");  
Console.WriteLine("Nullable double: value={0}", value == null ? "null" : value.ToString());  

This example produces the following output:

Nullable double: value=1.79769313486231E+308  

See also

Applies to

.NET 10 i druge verzije
Proizvod Verzije
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

Explicit(XAttribute to DateTimeOffset)

Source:
XAttribute.cs
Source:
XAttribute.cs
Source:
XAttribute.cs

Important

This API is not CLS-compliant.

Cast the value of this XAttribute to a DateTimeOffset.

C#
[System.CLSCompliant(false)]
public static explicit operator DateTimeOffset(System.Xml.Linq.XAttribute attribute);

Parameters

attribute
XAttribute

The XAttribute to cast to DateTimeOffset.

Returns

A DateTimeOffset that contains the content of this XAttribute.

Attributes

Exceptions

The attribute does not contain a valid DateTimeOffset value.

The attribute parameter is null.

Examples

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

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

// casting from a strictly formatted XML attribute  
DateTimeOffset dt = (DateTimeOffset)root.Attribute("Att");  
Console.WriteLine("dt={0}", dt);  

This example produces the following output:

<Root Att="2006-10-06T12:30:00-07:00" />  
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

.NET 10 i druge verzije
Proizvod Verzije
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

Explicit(XAttribute to DateTime)

Source:
XAttribute.cs
Source:
XAttribute.cs
Source:
XAttribute.cs

Important

This API is not CLS-compliant.

Cast the value of this XAttribute to a DateTime.

C#
[System.CLSCompliant(false)]
public static explicit operator DateTime(System.Xml.Linq.XAttribute attribute);

Parameters

attribute
XAttribute

The XAttribute to cast to DateTime.

Returns

A DateTime that contains the content of this XAttribute.

Attributes

Exceptions

The attribute does not contain a valid DateTime value.

The attribute parameter is null.

Examples

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

C#
// 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 XAttribute("Att", new DateTime(2006, 10, 6, 12, 30, 0))  
);  
Console.WriteLine(root);  

// casting from a strictly formatted XML attribute  
DateTime dt = (DateTime)root.Attribute("Att");  
Console.WriteLine("dt={0}", dt);  
Console.WriteLine("-----");  

// if root is formatted in some different way than the standard ISO 8601, if at all possible,  
// the value is appropriately converted to DateTime  

XAttribute dtAtt = new XAttribute("OrderDate", "October 6, 2006");  
Console.WriteLine(dtAtt);  
DateTime orderDate = (DateTime)dtAtt;  
Console.WriteLine("OrderDate={0:d}", orderDate);  

This example produces the following output:

<Root Att="2006-10-06T12:30:00" />  
dt=10/6/2006 12:30:00 PM  
-----  
OrderDate="October 6, 2006"  
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

.NET 10 i druge verzije
Proizvod Verzije
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

Explicit(XAttribute to Boolean)

Source:
XAttribute.cs
Source:
XAttribute.cs
Source:
XAttribute.cs

Important

This API is not CLS-compliant.

Cast the value of this XAttribute to a Boolean.

C#
[System.CLSCompliant(false)]
public static explicit operator bool(System.Xml.Linq.XAttribute attribute);

Parameters

attribute
XAttribute

The XAttribute to cast to Boolean.

Returns

A Boolean that contains the content of this XAttribute.

Attributes

Exceptions

The attribute does not contain a valid Boolean value.

The attribute parameter is null.

Examples

The following example creates an attribute with a Boolean value, then casts it to Boolean.

C#
XElement root = new XElement("Root",   
    new XAttribute("BoolValue", true)  
);  
bool bv = (bool)root.Attribute("BoolValue");  
Console.WriteLine("(bool)BoolValue={0}", bv);  

This example produces the following output:

(bool)BoolValue=True  

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

.NET 10 i druge verzije
Proizvod Verzije
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0