XAttribute.Explicit 運算子

定義

多載

Explicit(XAttribute to Nullable<Int64>)

將此 XAttribute 的值轉型為 Nullable<T>Int64

Explicit(XAttribute to Nullable<Single>)

將此 XAttribute 的值轉型為 Nullable<T>Single

Explicit(XAttribute to Nullable<TimeSpan>)

將此 XAttribute 的值轉型為 Nullable<T>TimeSpan

Explicit(XAttribute to Nullable<UInt32>)

將此 XAttribute 的值轉型為 Nullable<T>UInt32

Explicit(XAttribute to Nullable<UInt64>)

將此 XAttribute 的值轉型為 Nullable<T>UInt64

Explicit(XAttribute to TimeSpan)

將此 XAttribute 的值轉型為 TimeSpan

Explicit(XAttribute to String)

將此 XAttribute 的值轉型為 String

Explicit(XAttribute to Nullable<Int32>)

將此 XAttribute 的值轉型為 Nullable<T>Int32

Explicit(XAttribute to UInt32)

將此 XAttribute 的值轉型為 UInt32

Explicit(XAttribute to UInt64)

將此 XAttribute 的值轉型為 UInt64

Explicit(XAttribute to Single)

將此 XAttribute 的值轉型為 Single

Explicit(XAttribute to Nullable<Guid>)

將此 XAttribute 的值轉型為 Nullable<T>Guid

Explicit(XAttribute to Nullable<Decimal>)

將此 XAttribute 的值轉型為 Nullable<T>Decimal

Explicit(XAttribute to Decimal)

將此 XAttribute 的值轉型為 Decimal

Explicit(XAttribute to Nullable<DateTimeOffset>)

將此 XAttribute 的值轉型為 Nullable<T>DateTimeOffset

Explicit(XAttribute to Nullable<DateTime>)

將此 XAttribute 的值轉型為 Nullable<T>DateTime

Explicit(XAttribute to Nullable<Boolean>)

將此 XAttribute 的值轉型為 Nullable<T>Boolean

Explicit(XAttribute to Int64)

將此 XAttribute 的值轉型為 Int64

Explicit(XAttribute to Int32)

將此 XAttribute 的值轉型為 Int32

Explicit(XAttribute to Guid)

將此 XAttribute 的值轉型為 Guid

Explicit(XAttribute to Double)

將此 XAttribute 的值轉型為 Double

Explicit(XAttribute to Nullable<Double>)

將此 XAttribute 的值轉型為 Nullable<T>Double

Explicit(XAttribute to DateTimeOffset)

將此 XAttribute 的值轉型為 DateTimeOffset

Explicit(XAttribute to DateTime)

將此 XAttribute 的值轉型為 DateTime

Explicit(XAttribute to Boolean)

將此 XAttribute 的值轉型為 Boolean

Explicit(XAttribute to Nullable<Int64>)

重要

此 API 不符合 CLS 規範。

將此 XAttribute 的值轉型為 Nullable<T>Int64

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

參數

attribute
XAttribute

XAttribute,要轉型為 Nullable<T>Int64

傳回

Nullable<Int64>

Nullable<T>Int64,包含這個 XAttribute 的內容。

屬性

例外狀況

此屬性不包含有效的 Int64 值。

範例

下列範例會建立具有長整數內容的屬性。 然後,它會藉由轉換成 Nullable<T> Int64 來擷取值。

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());  
Dim root As XElement = <Root Att="9223372036854775807"/>  
Dim value As Nullable(Of Long) = CType(root.Attribute("Att"), Nullable(Of Long))  
Console.WriteLine("Nullable long: value={0}", IIf(value.HasValue, value.ToString(), "null"))  

這個範例會產生下列輸出:

Nullable long: value=9223372036854775807  

另請參閱

適用於

Explicit(XAttribute to Nullable<Single>)

重要

此 API 不符合 CLS 規範。

將此 XAttribute 的值轉型為 Nullable<T>Single

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

參數

attribute
XAttribute

XAttribute,要轉型為 Nullable<T>Single

傳回

Nullable<Single>

Nullable<T>Single,包含這個 XAttribute 的內容。

屬性

例外狀況

此屬性不包含有效的 Single 值。

範例

下列範例會建立具有單精確度浮點內容的屬性。 然後,它會藉由轉換成 Nullable<T> Single 來擷取值。

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());  
Dim root As XElement = <Root Att="3.402823E+38"/>  
Dim value As Nullable(Of Single) = CType(root.Attribute("Att"), Nullable(Of Single))  
Console.WriteLine("Nullable Single: value={0}", IIf(value.HasValue, value.ToString(), "null"))  

這個範例會產生下列輸出:

Nullable Single: value=3.402823E+38  

另請參閱

適用於

Explicit(XAttribute to Nullable<TimeSpan>)

重要

此 API 不符合 CLS 規範。

將此 XAttribute 的值轉型為 Nullable<T>TimeSpan

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

參數

attribute
XAttribute

XAttribute,要轉型為 Nullable<T>TimeSpan

傳回

Nullable<TimeSpan>

Nullable<T>TimeSpan,包含這個 XAttribute 的內容。

屬性

例外狀況

此屬性不包含有效的 TimeSpan 值。

範例

下列範例會建立具有時間範圍內容的屬性。 然後,它會藉由轉換成 Nullable<T> TimeSpan 來擷取值。

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());  
Dim root As XElement = <Root Att=<%= New TimeSpan(1, 5, 30) %>/>  
Dim value As Nullable(Of TimeSpan) = CType(root.Attribute("Att"), Nullable(Of TimeSpan))  
Console.WriteLine("Nullable TimeSpan: value={0}", IIf(value.HasValue, value.ToString(), "null"))  

這個範例會產生下列輸出:

Nullable TimeSpan: value=01:05:30  

備註

包含時間範圍內容之屬性或元素的值空間與持續時間內容緊密相關,如 ISO 8601 中所述。 建立包含時間範圍內容的屬性或專案時,會根據 W3C 規格格式化屬性或專案值。 如需詳細資訊,請參閱 W3C 規格。

當從屬性或元素轉換成 Nullable<T> TimeSpan 的 時,行為是延遲的。 即使屬性或專案值不是根據 W3C 規格完全格式化,值還是會適當地轉換成 Nullable<T>TimeSpan

另請參閱

適用於

Explicit(XAttribute to Nullable<UInt32>)

重要

此 API 不符合 CLS 規範。

將此 XAttribute 的值轉型為 Nullable<T>UInt32

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

參數

attribute
XAttribute

XAttribute,要轉型為 Nullable<T>UInt32

傳回

Nullable<UInt32>

Nullable<T>UInt32,包含這個 XAttribute 的內容。

屬性

例外狀況

此屬性不包含有效的 UInt32 值。

範例

下列範例會建立具有不帶正負號整數內容的屬性。 然後,它會藉由轉換成 Nullable<T> UInt32 來擷取值。

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());  
Dim root As XElement = <Root Att="4294967295"/>  
Dim value As Nullable(Of UInteger) = CType(root.Attribute("Att"), Nullable(Of UInteger))  
Console.WriteLine("Nullable uint: value={0}", IIf(value.HasValue, value.ToString(), "null"))  

這個範例會產生下列輸出:

Nullable uint: value=4294967295  

另請參閱

適用於

Explicit(XAttribute to Nullable<UInt64>)

重要

此 API 不符合 CLS 規範。

將此 XAttribute 的值轉型為 Nullable<T>UInt64

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

參數

attribute
XAttribute

XAttribute,要轉型為 Nullable<T>UInt64

傳回

Nullable<UInt64>

Nullable<T>UInt64,包含這個 XAttribute 的內容。

屬性

例外狀況

此屬性不包含有效的 UInt64 值。

範例

下列範例會建立具有不帶正負號長整數內容的屬性。 然後,它會藉由轉換成 Nullable<T> UInt64 來擷取值。

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());  
Dim root As XElement = <Root Att="9223372036854775807"/>  
Dim value As Nullable(Of ULong) = CType(root.Attribute("Att"), Nullable(Of ULong))  
Console.WriteLine("Nullable ulong: value={0}", IIf(value.HasValue, value.ToString(), "null"))  

這個範例會產生下列輸出:

Nullable ulong: value=9223372036854775807  

另請參閱

適用於

Explicit(XAttribute to TimeSpan)

重要

此 API 不符合 CLS 規範。

將此 XAttribute 的值轉型為 TimeSpan

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

參數

attribute
XAttribute

要轉型為 XAttributeTimeSpan

傳回

TimeSpan

TimeSpan,包含這個 XAttribute 的內容。

屬性

例外狀況

此屬性不包含有效的 TimeSpan 值。

attribute 參數為 null

範例

下列範例會建立具有時間範圍內容的屬性。 然後,它會藉由轉換成 TimeSpan 來擷取值。

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

這個範例會產生下列輸出:

value=01:05:30  

備註

包含時間範圍內容之屬性或元素的值空間與持續時間內容緊密相關,如 ISO 8601 中所述。 建立包含時間範圍內容的屬性或專案時,會根據 W3C 規格格式化屬性或專案值。 如需詳細資訊,請參閱 W3C 規格。

從屬性或專案轉換成 TimeSpan 時,行為是延遲的。 即使屬性或專案值並未完全符合 W3C 規格的格式,值還是會適當地轉換成 TimeSpan

另請參閱

適用於

Explicit(XAttribute to String)

重要

此 API 不符合 CLS 規範。

將此 XAttribute 的值轉型為 String

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

參數

attribute
XAttribute

要轉型為 XAttributeString

傳回

String

String,包含這個 XAttribute 的內容。

屬性

範例

下列範例會建立具有字串內容的屬性。 然後,它會藉由轉換成 String 來擷取值。

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);  
Dim root As XElement = <Root Att="attribute content"/>  
Dim att As XAttribute = root.Attribute("Att")  
Dim str As String = CStr(att)  
Console.WriteLine("(string)att={0}", str)  

這個範例會產生下列輸出:

(string)att=attribute content  

另請參閱

適用於

Explicit(XAttribute to Nullable<Int32>)

重要

此 API 不符合 CLS 規範。

將此 XAttribute 的值轉型為 Nullable<T>Int32

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

參數

attribute
XAttribute

XAttribute,要轉型為 Nullable<T>Int32

傳回

Nullable<Int32>

Nullable<T>Int32,包含這個 XAttribute 的內容。

屬性

範例

下列範例會建立具有整數內容的屬性。 然後,它會藉由轉換成 Nullable<T> Int32 來擷取值。

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());  
Dim root As XElement = <Root Att="2147483647"/>  
Dim value As Nullable(Of Integer) = CType(root.Attribute("Att"), Nullable(Of Integer))  
Console.WriteLine("Nullable int: value={0}", IIf(value.HasValue, value.ToString(), "null"))  

這個範例會產生下列輸出:

Nullable int: value=2147483647  

另請參閱

適用於

Explicit(XAttribute to UInt32)

重要

此 API 不符合 CLS 規範。

將此 XAttribute 的值轉型為 UInt32

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

參數

attribute
XAttribute

要轉型為 XAttributeUInt32

傳回

UInt32

UInt32,包含這個 XAttribute 的內容。

屬性

例外狀況

此屬性不包含有效的 UInt32 值。

attribute 參數為 null

範例

下列範例會建立具有不帶正負號整數內容的屬性。 然後,它會藉由轉換成 UInt32 來擷取值。

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

這個範例會產生下列輸出:

value=4294967295  

另請參閱

適用於

Explicit(XAttribute to UInt64)

重要

此 API 不符合 CLS 規範。

將此 XAttribute 的值轉型為 UInt64

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

參數

attribute
XAttribute

要轉型為 XAttributeUInt64

傳回

UInt64

UInt64,包含這個 XAttribute 的內容。

屬性

例外狀況

此屬性不包含有效的 UInt64 值。

attribute 參數為 null

範例

下列範例會建立具有不帶正負號長整數內容的屬性。 然後,它會藉由轉換成 UInt64 來擷取值。

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

這個範例會產生下列輸出:

value=1844674407370955161  

另請參閱

適用於

Explicit(XAttribute to Single)

重要

此 API 不符合 CLS 規範。

將此 XAttribute 的值轉型為 Single

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

參數

attribute
XAttribute

要轉型為 XAttributeSingle

傳回

Single

Single,包含這個 XAttribute 的內容。

屬性

例外狀況

此屬性不包含有效的 Single 值。

attribute 參數為 null

範例

下列範例會建立具有單精確度浮點內容的屬性。 然後,它會藉由轉換成 Single 來擷取值。

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

這個範例會產生下列輸出:

value=3.402823E+38  

另請參閱

適用於

Explicit(XAttribute to Nullable<Guid>)

重要

此 API 不符合 CLS 規範。

將此 XAttribute 的值轉型為 Nullable<T>Guid

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

參數

attribute
XAttribute

XAttribute,要轉型為 Nullable<T>Guid

傳回

Nullable<Guid>

Nullable<T>Guid,包含這個 XAttribute 的內容。

屬性

例外狀況

此屬性不包含有效的 Guid 值。

範例

下列範例會建立具有 guid 內容的屬性。 然後,它會藉由轉換成 Nullable<T> Guid 來擷取值。

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());  
Dim root As XElement = <Root Att=<%= New Guid("3c1cc55b-baff-4b7a-9d17-077af3aa5730") %>/>  
Dim value As Nullable(Of Guid) = CType(root.Attribute("Att"), Nullable(Of Guid))  
Console.WriteLine("Nullable Guid: value={0}", IIf(value.HasValue, value.ToString(), "null"))  

這個範例會產生下列輸出:

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

另請參閱

適用於

Explicit(XAttribute to Nullable<Decimal>)

重要

此 API 不符合 CLS 規範。

將此 XAttribute 的值轉型為 Nullable<T>Decimal

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

參數

attribute
XAttribute

XAttribute,要轉型為 Nullable<T>Decimal

傳回

Nullable<Decimal>

Nullable<T>Decimal,包含這個 XAttribute 的內容。

屬性

例外狀況

此屬性不包含有效的 Decimal 值。

範例

下列範例會建立具有十進位內容的屬性。 然後,它會藉由轉換成 Nullable<T> Decimal 來擷取值。

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());  
Dim root As XElement = <Root Att="79228162514264337593543950335"/>  
Dim value As Nullable(Of Decimal) = CType(root.Attribute("Att"), Nullable(Of Decimal))  
Console.WriteLine("Nullable decimal: value={0}", IIf(value.HasValue, value.ToString(), "null"))  

這個範例會產生下列輸出:

Nullable decimal: value=79228162514264337593543950335  

另請參閱

適用於

Explicit(XAttribute to Decimal)

重要

此 API 不符合 CLS 規範。

將此 XAttribute 的值轉型為 Decimal

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

參數

attribute
XAttribute

要轉型為 XAttributeDecimal

傳回

Decimal

Decimal,包含這個 XAttribute 的內容。

屬性

例外狀況

此屬性不包含有效的 Decimal 值。

attribute 參數為 null

範例

下列範例會建立具有十進位值的屬性。 然後,它會藉由轉換成 Decimal 來擷取屬性的值。

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

這個範例會產生下列輸出:

value=79228162514264337593543950335  

另請參閱

適用於

Explicit(XAttribute to Nullable<DateTimeOffset>)

重要

此 API 不符合 CLS 規範。

將此 XAttribute 的值轉型為 Nullable<T>DateTimeOffset

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

參數

attribute
XAttribute

XAttribute,要轉型為 Nullable<T>DateTimeOffset

傳回

Nullable<DateTimeOffset>

Nullable<T>DateTimeOffset,包含這個 XAttribute 的內容。

屬性

例外狀況

此屬性不包含有效的 DateTimeOffset 值。

範例

下列範例會建立具有日期和時間做為內容的屬性。 然後,它會藉由轉換成 Nullable<T> DateTimeOffset 來擷取值。

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());  
Dim root As XElement = _  
    <Root  
        Att=<%= New DateTimeOffset(New DateTime(2006, 10, 6, 12, 30, 0)) %>/>  
Dim value As Nullable(Of DateTimeOffset) = CType(root.Attribute("Att"), Nullable(Of DateTimeOffset))  
Console.WriteLine("Nullable DateTimeOffset: value={0}", IIf(value.HasValue, value.ToString(), "null"))  

這個範例會產生下列輸出:

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

備註

這個轉換運算子會 XmlConvert 使用 類別來執行轉換。

適用於

Explicit(XAttribute to Nullable<DateTime>)

重要

此 API 不符合 CLS 規範。

將此 XAttribute 的值轉型為 Nullable<T>DateTime

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

參數

attribute
XAttribute

XAttribute,要轉型為 Nullable<T>DateTime

傳回

Nullable<DateTime>

Nullable<T>DateTime,包含這個 XAttribute 的內容。

屬性

例外狀況

此屬性不包含有效的 DateTime 值。

範例

下列範例會建立具有日期和時間做為內容的屬性。 然後,它會藉由轉換成 Nullable<T> DateTime 來擷取值。

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());  
Dim root As XElement = <Root Att=<%= New DateTime(2006, 10, 6, 12, 30, 0) %>/>  
Dim value As Nullable(Of DateTime) = CType(root.Attribute("Att"), Nullable(Of DateTime))  
Console.WriteLine("Nullable DateTime: value={0}", IIf(value.HasValue, value.ToString(), "null"))  

這個範例會產生下列輸出:

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

備註

包含日期和時間內容之屬性或元素的值空間與 ISO 8601 中所述的日期和時間緊密相關。 建立包含日期和時間內容的屬性或專案時,會根據 W3C 規格來格式化屬性或專案值。 如需詳細資訊,請參閱 W3C 規格。

從屬性或專案轉換成 Nullable<T>DateTime 時,行為是 lax。 即使屬性或專案值不是根據 W3C 規格完全格式化,值還是會適當地轉換成 Nullable<T>DateTime

這個轉換運算子會使用 CultureInfo.InvariantCultureDateTime 轉換。

另請參閱

適用於

Explicit(XAttribute to Nullable<Boolean>)

重要

此 API 不符合 CLS 規範。

將此 XAttribute 的值轉型為 Nullable<T>Boolean

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

參數

attribute
XAttribute

XAttribute,要轉型為 Nullable<T>Boolean

傳回

Nullable<Boolean>

Nullable<T>Boolean,包含這個 XAttribute 的內容。

屬性

例外狀況

此屬性不包含有效的 Boolean 值。

範例

下列範例會建立具有布林內容的屬性。 然後,它會藉由轉換成 Nullable<T> Boolean 來擷取值。

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);  
Dim root As XElement = <Root BoolValue1="true" BoolValue2="false"/>  
Dim bool1 As Nullable(Of Boolean) = CType(root.Attribute("BoolValue1"), Nullable(Of Boolean))  
Dim bool2 As Nullable(Of Boolean) = CType(root.Attribute("BoolValue2"), Nullable(Of Boolean))  
Console.WriteLine("Nullable boolean: BoolValue1={0}", bool1)  
Console.WriteLine("Nullable boolean: BoolValue2={0}", bool2)  

這個範例會產生下列輸出:

Nullable boolean: BoolValue1=True  
Nullable boolean: BoolValue2=False  

備註

從屬性或元素轉換成 Boolean 時,允許的值是 「0」、「1」,以及修剪並轉換成小寫之後產生 「true」 或 「false」 的任何字串。

另請參閱

適用於

Explicit(XAttribute to Int64)

重要

此 API 不符合 CLS 規範。

將此 XAttribute 的值轉型為 Int64

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

參數

attribute
XAttribute

要轉型為 XAttributeInt64

傳回

Int64

Int64,包含這個 XAttribute 的內容。

屬性

例外狀況

此屬性不包含有效的 Int64 值。

attribute 參數為 null

範例

下列範例會建立具有長整數做為內容的屬性。 然後,它會藉由轉換成 Int64 來擷取屬性的值。

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

這個範例會產生下列輸出:

value=9223372036854775807  

另請參閱

適用於

Explicit(XAttribute to Int32)

重要

此 API 不符合 CLS 規範。

將此 XAttribute 的值轉型為 Int32

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

參數

attribute
XAttribute

要轉型為 XAttributeInt32

傳回

Int32

Int32,包含這個 XAttribute 的內容。

屬性

例外狀況

此屬性不包含有效的 Int32 值。

attribute 參數為 null

範例

下列範例會建立具有整數做為內容的屬性。 然後,它會藉由轉換成 Int32 來擷取值。

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

這個範例會產生下列輸出:

value=2147483647  

另請參閱

適用於

Explicit(XAttribute to Guid)

重要

此 API 不符合 CLS 規範。

將此 XAttribute 的值轉型為 Guid

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

參數

attribute
XAttribute

要轉型為 XAttributeGuid

傳回

Guid

Guid,包含這個 XAttribute 的內容。

屬性

例外狀況

此屬性不包含有效的 Guid 值。

attribute 參數為 null

範例

下列範例會建立具有 GUID 做為內容的屬性。 然後,它會藉由轉換成 Guid 來擷取值。

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

這個範例會產生下列輸出:

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

另請參閱

適用於

Explicit(XAttribute to Double)

重要

此 API 不符合 CLS 規範。

將此 XAttribute 的值轉型為 Double

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

參數

attribute
XAttribute

要轉型為 XAttributeDouble

傳回

Double

Double,包含這個 XAttribute 的內容。

屬性

例外狀況

此屬性不包含有效的 Double 值。

attribute 參數為 null

範例

下列範例會建立具有 Double 內容的屬性。 然後,它會藉由轉換成 Double 來擷取值。

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

這個範例會產生下列輸出:

value=1.79769313486231E+308  

另請參閱

適用於

Explicit(XAttribute to Nullable<Double>)

重要

此 API 不符合 CLS 規範。

將此 XAttribute 的值轉型為 Nullable<T>Double

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

參數

attribute
XAttribute

XAttribute,要轉型為 Nullable<T>Double

傳回

Nullable<Double>

Nullable<T>Double,包含這個 XAttribute 的內容。

屬性

例外狀況

此屬性不包含有效的 Double 值。

範例

下列範例會建立具有雙精確度浮點內容的屬性。 然後,它會藉由轉換成 Nullable<T> Double 來擷取值。

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());  
Dim root As XElement = <Root Att="1.79769313486231E+308"/>  
Dim value As Nullable(Of Double) = CType(root.Attribute("Att"), Nullable(Of Double))  
Console.WriteLine("Nullable double: value={0}", IIf(value.HasValue, value.ToString(), "null"))  

這個範例會產生下列輸出:

Nullable double: value=1.79769313486231E+308  

另請參閱

適用於

Explicit(XAttribute to DateTimeOffset)

重要

此 API 不符合 CLS 規範。

將此 XAttribute 的值轉型為 DateTimeOffset

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

參數

attribute
XAttribute

要轉型為 XAttributeDateTimeOffset

傳回

DateTimeOffset

DateTimeOffset,包含這個 XAttribute 的內容。

屬性

例外狀況

此屬性不包含有效的 DateTimeOffset 值。

attribute 參數為 null

範例

下列範例會建立具有日期和時間內容的屬性。 然後將它 DateTimeOffset 轉換成 以擷取值。

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);  
Dim root As XElement = _  
    <Root  
        Att=<%= New DateTimeOffset(New DateTime(2006, 10, 6, 12, 30, 0)) %>/>  
Console.WriteLine(root)  

' casting from a strictly formatted XML attribute  
Dim dt As DateTimeOffset = CType(root.Attribute("Att"), DateTimeOffset)  
Console.WriteLine("dt={0}", dt)  

這個範例會產生下列輸出:

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

備註

這個轉換運算子會 XmlConvert 使用 類別來執行轉換。

另請參閱

適用於

Explicit(XAttribute to DateTime)

重要

此 API 不符合 CLS 規範。

將此 XAttribute 的值轉型為 DateTime

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

參數

attribute
XAttribute

要轉型為 XAttributeDateTime

傳回

DateTime

DateTime,包含這個 XAttribute 的內容。

屬性

例外狀況

此屬性不包含有效的 DateTime 值。

attribute 參數為 null

範例

下列範例會建立具有日期和時間內容的屬性。 然後將它 DateTime 轉換成 以擷取值。

// 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);  
' 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 Att=<%= New DateTime(2006, 10, 6, 12, 30, 0) %>/>  

Console.WriteLine(root)  

' casting from a strictly formatted XML attribute  
Dim dt As DateTime = CType(root.Attribute("Att"), DateTime)  
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  
Dim dtAtt As XAttribute = New XAttribute("OrderDate", "October 6, 2006")  
Console.WriteLine(dtAtt)  
Dim orderDate As DateTime = CType(dtAtt, DateTime)  
Console.WriteLine("OrderDate={0:d}", orderDate)  

這個範例會產生下列輸出:

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

備註

包含日期和時間內容之屬性或元素的值空間與 ISO 8601 中所述的日期和時間緊密相關。 建立包含日期和時間內容的屬性或專案時,會根據 W3C 規格來格式化屬性或專案值。 如需詳細資訊,請參閱 W3C 規格。

從屬性或專案轉換成 DateTime 時,行為是 lax。 即使屬性或專案值並未完全符合 W3C 規格的格式,值還是會適當地轉換成 DateTime

這個轉換運算子會使用 CultureInfo.InvariantCultureDateTime 轉換。

另請參閱

適用於

Explicit(XAttribute to Boolean)

重要

此 API 不符合 CLS 規範。

將此 XAttribute 的值轉型為 Boolean

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

參數

attribute
XAttribute

要轉型為 XAttributeBoolean

傳回

Boolean

Boolean,包含這個 XAttribute 的內容。

屬性

例外狀況

此屬性不包含有效的 Boolean 值。

attribute 參數為 null

範例

下列範例會建立具有 Boolean 值的屬性,然後將它 Boolean 轉換成 。

XElement root = new XElement("Root",   
    new XAttribute("BoolValue", true)  
);  
bool bv = (bool)root.Attribute("BoolValue");  
Console.WriteLine("(bool)BoolValue={0}", bv);  
Dim root As XElement = <root BoolValue="true"/>  
Dim bv As Boolean = CBool(root.Attribute("BoolValue"))  
Console.WriteLine("(bool)BoolValue={0}", bv)  

這個範例會產生下列輸出:

(bool)BoolValue=True  

備註

從屬性或元素轉換成 Boolean 時,允許的值是 「0」、「1」,以及修剪並轉換成小寫之後產生 「true」 或 「false」 的任何字串。

另請參閱

適用於