XElement.Explicit 運算子

定義

多載

Explicit(XElement to Nullable<Int64>)

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

Explicit(XElement to Nullable<Single>)

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

Explicit(XElement to Nullable<TimeSpan>)

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

Explicit(XElement to Nullable<UInt32>)

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

Explicit(XElement to Nullable<UInt64>)

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

Explicit(XElement to UInt32)

將此 XElement 的值轉型為 UInt32

Explicit(XElement to String)

將此 XElement 的值轉型為 String

Explicit(XElement to TimeSpan)

將此 XElement 的值轉型為 TimeSpan

Explicit(XElement to UInt64)

將此 XElement 的值轉型為 UInt64

Explicit(XElement to Nullable<Int32>)

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

Explicit(XElement to Single)

將此 XElement 的值轉型為 Single

Explicit(XElement to Nullable<Guid>)

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

Explicit(XElement to Nullable<Boolean>)

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

Explicit(XElement to Nullable<Decimal>)

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

Explicit(XElement to Boolean)

將此 XElement 的值轉型為 Boolean

Explicit(XElement to DateTime)

將此 XElement 的值轉型為 DateTime

Explicit(XElement to DateTimeOffset)

將此 XAttribute 的值轉型為 DateTimeOffset

Explicit(XElement to Double)

將此 XElement 的值轉型為 Double

Explicit(XElement to Guid)

將此 XElement 的值轉型為 Guid

Explicit(XElement to Decimal)

將此 XElement 的值轉型為 Decimal

Explicit(XElement to Int64)

將此 XElement 的值轉型為 Int64

Explicit(XElement to Nullable<Double>)

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

Explicit(XElement to Nullable<DateTime>)

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

Explicit(XElement to Nullable<DateTimeOffset>)

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

Explicit(XElement to Int32)

將此 XElement 的值轉型為 Int32

Explicit(XElement to Nullable<Int64>)

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

重要

此 API 不符合 CLS 規範。

將此 XElement 的值轉型為 Nullable<T>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)

參數

element
XElement

XElement,要轉型為 Nullable<T>Int64

傳回

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

屬性

例外狀況

元素不是 null 且不包含有效的 Int64 值。

範例

下列範例會建立具有長整數內容的元素。 然後,它會藉由轉換成 Nullable<T>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"))

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

Nullable ulong: value=9223372036854775807

另請參閱

適用於

Explicit(XElement to Nullable<Single>)

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

重要

此 API 不符合 CLS 規範。

將此 XElement 的值轉型為 Nullable<T>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)

參數

element
XElement

XElement,要轉型為 Nullable<T>Single

傳回

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

屬性

例外狀況

元素不是 null 且不包含有效的 Single 值。

範例

下列範例會建立具有單精確度浮點內容的專案。 然後,它會藉由轉換成 Nullable<T>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"))

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

Nullable Single: value=3.402823E+38

另請參閱

適用於

Explicit(XElement to Nullable<TimeSpan>)

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

重要

此 API 不符合 CLS 規範。

將此 XElement 的值轉型為 Nullable<T>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)

參數

element
XElement

XElement,要轉型為 Nullable<T>TimeSpan

傳回

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

屬性

例外狀況

元素不是 null 且不包含有效的 TimeSpan 值。

範例

下列範例會建立具有時間範圍內容的元素。 然後,它會藉由轉換成 Nullable<T>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"))

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

Nullable TimeSpan: value=01:05:30

備註

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

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

另請參閱

適用於

Explicit(XElement to Nullable<UInt32>)

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

重要

此 API 不符合 CLS 規範。

將此 XElement 的值轉型為 Nullable<T>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)

參數

element
XElement

XElement,要轉型為 Nullable<T>UInt32

傳回

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

屬性

例外狀況

元素不是 null 且不包含有效的 UInt32 值。

範例

下列範例會建立具有不帶正負號整數內容的元素。 然後,它會藉由轉換成 Nullable<T>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"))

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

Nullable uint: value=4294967295

另請參閱

適用於

Explicit(XElement to Nullable<UInt64>)

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

重要

此 API 不符合 CLS 規範。

將此 XElement 的值轉型為 Nullable<T>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)

參數

element
XElement

XElement,要轉型為 Nullable<T>UInt64

傳回

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

屬性

例外狀況

元素不是 null 且不包含有效的 UInt64 值。

範例

下列範例會建立具有不帶正負號長整數內容的專案。 然後,它會藉由轉換成 Nullable<T>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"))

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

Nullable ulong: value=9223372036854775807

另請參閱

適用於

Explicit(XElement to UInt32)

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

重要

此 API 不符合 CLS 規範。

將此 XElement 的值轉型為 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

參數

element
XElement

要轉型為 XElementUInt32

傳回

UInt32,包含這個 XElement 的內容。

屬性

例外狀況

項目不包含有效的 UInt32 值。

element 參數為 null

範例

下列範例會建立具有不帶正負號整數內容的元素。 然後,它會藉由轉換成 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)

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

value=4294967295

另請參閱

適用於

Explicit(XElement to String)

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

重要

此 API 不符合 CLS 規範。

將此 XElement 的值轉型為 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

參數

element
XElement

要轉型為 XElementString

傳回

String,包含這個 XElement 的內容。

屬性

範例

下列範例會建立具有字串內容的專案。 然後,它會藉由轉換成 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)

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

(string)root=abc def ghi

備註

XElement如果 具有子系,則會傳回所有元素文字和子系文字的串連字號串值。

另請參閱

適用於

Explicit(XElement to TimeSpan)

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

重要

此 API 不符合 CLS 規範。

將此 XElement 的值轉型為 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

參數

element
XElement

要轉型為 XElementTimeSpan

傳回

TimeSpan,包含這個 XElement 的內容。

屬性

例外狀況

項目不包含有效的 TimeSpan 值。

element 參數為 null

範例

下列範例會建立具有時間範圍內容的專案。 然後,它會藉由轉換成 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)

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

value=01:05:30

備註

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

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

另請參閱

適用於

Explicit(XElement to UInt64)

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

重要

此 API 不符合 CLS 規範。

將此 XElement 的值轉型為 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

參數

element
XElement

要轉型為 XElementUInt64

傳回

UInt64,包含這個 XElement 的內容。

屬性

例外狀況

項目不包含有效的 UInt64 值。

element 參數為 null

elementnull

範例

下列範例會建立具有不帶正負號長整數內容的專案。 然後,它會藉由轉換成 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)

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

value=18446744073709551615

另請參閱

適用於

Explicit(XElement to Nullable<Int32>)

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

重要

此 API 不符合 CLS 規範。

將此 XElement 的值轉型為 Nullable<T>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)

參數

element
XElement

XElement,要轉型為 Nullable<T>Int32

傳回

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

屬性

例外狀況

元素不是 null 且不包含有效的 Int32 值。

範例

下列範例會建立具有不帶正負號整數內容的專案。 然後,它會藉由轉換成 Nullable<T>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"))

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

Nullable integer: value=2147483647

另請參閱

適用於

Explicit(XElement to Single)

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

重要

此 API 不符合 CLS 規範。

將此 XElement 的值轉型為 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

參數

element
XElement

要轉型為 XElementSingle

傳回

Single,包含這個 XElement 的內容。

屬性

例外狀況

項目不包含有效的 Single 值。

element 參數為 null

elementnull

範例

下列範例會建立具有單精確度浮點內容的專案。 然後,它會藉由轉換成 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)

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

value=3.402823E+38

另請參閱

適用於

Explicit(XElement to Nullable<Guid>)

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

重要

此 API 不符合 CLS 規範。

將此 XElement 的值轉型為 Nullable<T>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)

參數

element
XElement

XElement,要轉型為 Nullable<T>Guid

傳回

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

屬性

例外狀況

元素不是 null 且不包含有效的 Guid 值。

範例

下列範例會建立具有 guid 內容的專案。 然後,它會藉由轉換成 Nullable<T>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"))

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

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

另請參閱

適用於

Explicit(XElement to Nullable<Boolean>)

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

重要

此 API 不符合 CLS 規範。

將此 XElement 的值轉型為 Nullable<T>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)

參數

element
XElement

XElement,要轉型為 Nullable<T>Boolean

傳回

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

屬性

例外狀況

元素不是 null 且不包含有效的 Boolean 值。

範例

下列範例會建立具有布林內容的專案。 然後,它會藉由轉換成 Nullable<T>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"))

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

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

備註

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

另請參閱

適用於

Explicit(XElement to Nullable<Decimal>)

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

重要

此 API 不符合 CLS 規範。

將此 XElement 的值轉型為 Nullable<T>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)

參數

element
XElement

XElement,要轉型為 Nullable<T>Decimal

傳回

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

屬性

例外狀況

元素不是 null 且不包含有效的 Decimal 值。

範例

下列範例會建立具有十進位內容的專案。 然後,它會藉由轉換成 Nullable<T>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"))

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

Nullable decimal: value=79228162514264337593543950335

另請參閱

適用於

Explicit(XElement to Boolean)

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

重要

此 API 不符合 CLS 規範。

將此 XElement 的值轉型為 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

參數

element
XElement

要轉型為 XElementBoolean

傳回

Boolean,包含這個 XElement 的內容。

屬性

例外狀況

項目不包含有效的 Boolean 值。

element 參數為 null

範例

下列範例會建立一些具有布林值的元素。 然後,它會將它們轉換成 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)

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

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

備註

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

另請參閱

適用於

Explicit(XElement to DateTime)

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

重要

此 API 不符合 CLS 規範。

將此 XElement 的值轉型為 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

參數

element
XElement

要轉型為 XElementDateTime

傳回

DateTime,包含這個 XElement 的內容。

屬性

例外狀況

項目不包含有效的 DateTime 值。

element 參數為 null

elementnull

範例

下列範例會建立具有日期和時間內容的專案。 然後將它 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 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)

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

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

備註

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

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

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

另請參閱

適用於

Explicit(XElement to DateTimeOffset)

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

重要

此 API 不符合 CLS 規範。

將此 XAttribute 的值轉型為 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

參數

element
XElement

要轉型為 XElementDateTimeOffset

傳回

DateTimeOffset,包含這個 XElement 的內容。

屬性

例外狀況

項目不包含有效的 DateTimeOffset 值。

element 參數為 null

elementnull

範例

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

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)

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

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

備註

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

另請參閱

適用於

Explicit(XElement to Double)

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

重要

此 API 不符合 CLS 規範。

將此 XElement 的值轉型為 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

參數

element
XElement

要轉型為 XElementDouble

傳回

Double,包含這個 XElement 的內容。

屬性

例外狀況

項目不包含有效的 Double 值。

element 參數為 null

elementnull

範例

下列範例會建立具有 double 內容的屬性。 然後,它會藉由轉換成 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)

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

value=1.79769313486231E+308

另請參閱

適用於

Explicit(XElement to Guid)

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

重要

此 API 不符合 CLS 規範。

將此 XElement 的值轉型為 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

參數

element
XElement

要轉型為 XElementGuid

傳回

Guid,包含這個 XElement 的內容。

屬性

例外狀況

項目不包含有效的 Guid 值。

element 參數為 null

elementnull

範例

下列範例會建立具有 guid 做為內容的專案。 然後,它會藉由轉換成 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)

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

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

另請參閱

適用於

Explicit(XElement to Decimal)

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

重要

此 API 不符合 CLS 規範。

將此 XElement 的值轉型為 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

參數

element
XElement

要轉型為 XElementDecimal

傳回

Decimal,包含這個 XElement 的內容。

屬性

例外狀況

項目不包含有效的 Decimal 值。

element 參數為 null

elementnull

範例

下列範例會建立具有十進位值的 元素。 然後,它會藉由轉換成 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)

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

value=79228162514264337593543950335

另請參閱

適用於

Explicit(XElement to Int64)

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

重要

此 API 不符合 CLS 規範。

將此 XElement 的值轉型為 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

參數

element
XElement

要轉型為 XElementInt64

傳回

Int64,包含這個 XElement 的內容。

屬性

例外狀況

項目不包含有效的 Int64 值。

element 參數為 null

elementnull

範例

下列範例會建立包含長整數做為內容的專案。 然後,它會藉由轉換成 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)

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

value=9223372036854775807

另請參閱

適用於

Explicit(XElement to Nullable<Double>)

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

重要

此 API 不符合 CLS 規範。

將此 XElement 的值轉型為 Nullable<T>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)

參數

element
XElement

XElement,要轉型為 Nullable<T>Double

傳回

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

屬性

例外狀況

元素不是 null 且不包含有效的 Double 值。

範例

下列範例會建立具有雙精確度浮點內容的專案。 然後,它會藉由轉換成 Nullable<T>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"))

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

Nullable double: value=1.79769313486231E+308

另請參閱

適用於

Explicit(XElement to Nullable<DateTime>)

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

重要

此 API 不符合 CLS 規範。

將此 XElement 的值轉型為 Nullable<T>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)

參數

element
XElement

XElement,要轉型為 Nullable<T>DateTime

傳回

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

屬性

例外狀況

元素不是 null 且不包含有效的 DateTime 值。

範例

下列範例會建立具有日期和時間做為內容的專案。 然後,它會藉由轉換成 Nullable<T>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"))

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

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(XElement to Nullable<DateTimeOffset>)

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

重要

此 API 不符合 CLS 規範。

將此 XElement 的值轉型為 Nullable<T>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)

參數

element
XElement

XElement,要轉型為 Nullable<T>DateTimeOffset

傳回

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

屬性

例外狀況

元素不是 null 且不包含有效的 DateTimeOffset 值。

範例

下列範例會建立具有日期和時間內容的專案。 然後,它會轉換成 Nullable<T>DateTimeOffset 擷取值。

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)

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

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

備註

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

另請參閱

適用於

Explicit(XElement to Int32)

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

重要

此 API 不符合 CLS 規範。

將此 XElement 的值轉型為 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

參數

element
XElement

要轉型為 XElementInt32

傳回

Int32,包含這個 XElement 的內容。

屬性

例外狀況

項目不包含有效的 Int32 值。

element 參數為 null

範例

下列範例會建立具有整數做為內容的專案。 然後,它會藉由轉換成 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)

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

value=2147483647

另請參閱

適用於