XAttribute.Explicit 操作员
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
重载
Explicit(XAttribute to Nullable<Int64>)
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
重要
此 API 不符合 CLS。
将此值
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<T>一个Int64包含此XAttribute内容。
- 属性
例外
该属性不包含有效 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>)
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
重要
此 API 不符合 CLS。
将此值
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<T>一个Single包含此XAttribute内容。
- 属性
例外
该属性不包含有效 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>)
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
重要
此 API 不符合 CLS。
将此值
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<T>一个TimeSpan包含此XAttribute内容。
- 属性
例外
该属性不包含有效 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 规范进行格式设置,值也适当地转换为 <
另请参阅
适用于
Explicit(XAttribute to Nullable<UInt32>)
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
重要
此 API 不符合 CLS。
将此值
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<T>一个UInt32包含此XAttribute内容。
- 属性
例外
该属性不包含有效 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>)
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
重要
此 API 不符合 CLS。
将此值
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<T>一个UInt64包含此XAttribute内容。
- 属性
例外
该属性不包含有效 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)
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
重要
此 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
要 XAttribute 强制转换为 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 规范进行格式设置,该值也会适当地转换为 a TimeSpan。
另请参阅
适用于
Explicit(XAttribute to String)
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
重要
此 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
要 XAttribute 强制转换为 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>)
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
重要
此 API 不符合 CLS。
将此值
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<T>一个Int32包含此XAttribute内容。
- 属性
示例
以下示例创建一个包含整数内容的属性。 然后,它通过强制转换为
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)
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
重要
此 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
要 XAttribute 强制转换为 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)
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
重要
此 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
要 XAttribute 强制转换为 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)
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
重要
此 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
要 XAttribute 强制转换为 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>)
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
重要
此 API 不符合 CLS。
将此值
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<T>一个Guid包含此XAttribute内容。
- 属性
例外
该属性不包含有效 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("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>)
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
重要
此 API 不符合 CLS。
将此值
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<T>一个Decimal包含此XAttribute内容。
- 属性
例外
该属性不包含有效 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)
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
重要
此 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
要 XAttribute 强制转换为 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>)
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
重要
此 API 不符合 CLS。
将此值
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<T>一个DateTimeOffset包含此XAttribute内容。
- 属性
例外
该属性不包含有效 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>)
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
重要
此 API 不符合 CLS。
将此值
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<T>一个DateTime包含此XAttribute内容。
- 属性
例外
该属性不包含有效 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的行为很宽松。 即使属性或元素值未完全按照 W3C 规范进行格式设置,值也适当地转换为 <
此转换运算符用于 CultureInfo.InvariantCulture 从 . DateTime.
另请参阅
适用于
Explicit(XAttribute to Nullable<Boolean>)
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
重要
此 API 不符合 CLS。
将此值
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<T>一个Boolean包含此XAttribute内容。
- 属性
例外
该属性不包含有效 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)
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
重要
此 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
要 XAttribute 强制转换为 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)
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
重要
此 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
要 XAttribute 强制转换为 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)
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
重要
此 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
要 XAttribute 强制转换为 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)
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
重要
此 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
要 XAttribute 强制转换为 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>)
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
重要
此 API 不符合 CLS。
将此值
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<T>一个Double包含此XAttribute内容。
- 属性
例外
该属性不包含有效 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)
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
重要
此 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
要 XAttribute 强制转换为 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)
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
重要
此 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
要 XAttribute 强制转换为 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 行为时行为很宽松。 即使属性或元素值未完全按照 W3C 规范进行格式设置,该值也会适当地转换为 a DateTime。
此转换运算符用于 CultureInfo.InvariantCulture 从 . DateTime.
另请参阅
适用于
Explicit(XAttribute to Boolean)
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
重要
此 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
要 XAttribute 强制转换为 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”的任何字符串。