XAttribute.Explicit Operator

Definition

Överlagringar

Name Description
Explicit(XAttribute to Nullable<Int64>)

Omvandla värdet för detta XAttribute till en Nullable<T> av Int64.

Explicit(XAttribute to Nullable<Single>)

Omvandla värdet för detta XAttribute till en Nullable<T> av Single.

Explicit(XAttribute to Nullable<TimeSpan>)

Omvandla värdet för detta XAttribute till en Nullable<T> av TimeSpan.

Explicit(XAttribute to Nullable<UInt32>)

Omvandla värdet för detta XAttribute till en Nullable<T> av UInt32.

Explicit(XAttribute to Nullable<UInt64>)

Omvandla värdet för detta XAttribute till en Nullable<T> av UInt64.

Explicit(XAttribute to TimeSpan)

Omvandla värdet för detta XAttribute till en TimeSpan.

Explicit(XAttribute to String)

Omvandla värdet för detta XAttribute till en String.

Explicit(XAttribute to Nullable<Int32>)

Omvandla värdet för detta XAttribute till en Nullable<T> av Int32.

Explicit(XAttribute to UInt32)

Omvandla värdet för detta XAttribute till en UInt32.

Explicit(XAttribute to UInt64)

Omvandla värdet för detta XAttribute till en UInt64.

Explicit(XAttribute to Single)

Omvandla värdet för detta XAttribute till en Single.

Explicit(XAttribute to Nullable<Guid>)

Omvandla värdet för detta XAttribute till en Nullable<T> av Guid.

Explicit(XAttribute to Nullable<Decimal>)

Omvandla värdet för detta XAttribute till en Nullable<T> av Decimal.

Explicit(XAttribute to Decimal)

Omvandla värdet för detta XAttribute till en Decimal.

Explicit(XAttribute to Nullable<DateTimeOffset>)

Omvandla värdet för detta XAttribute till en Nullable<T> av DateTimeOffset.

Explicit(XAttribute to Nullable<DateTime>)

Omvandla värdet för detta XAttribute till en Nullable<T> av DateTime.

Explicit(XAttribute to Nullable<Boolean>)

Omvandla värdet för detta XAttribute till en Nullable<T> av Boolean.

Explicit(XAttribute to Int64)

Omvandla värdet för detta XAttribute till en Int64.

Explicit(XAttribute to Int32)

Omvandla värdet för detta XAttribute till en Int32.

Explicit(XAttribute to Guid)

Omvandla värdet för detta XAttribute till en Guid.

Explicit(XAttribute to Double)

Omvandla värdet för detta XAttribute till en Double.

Explicit(XAttribute to Nullable<Double>)

Omvandla värdet för detta XAttribute till en Nullable<T> av Double.

Explicit(XAttribute to DateTimeOffset)

Omvandla värdet för detta XAttribute till en DateTimeOffset.

Explicit(XAttribute to DateTime)

Omvandla värdet för detta XAttribute till en DateTime.

Explicit(XAttribute to Boolean)

Omvandla värdet för detta XAttribute till en Boolean.

Explicit(XAttribute to Nullable<Int64>)

Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs

Viktigt!

Detta API uppfyller inte CLS.

Omvandla värdet för detta XAttribute till en Nullable<T> av 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)

Parametrar

attribute
XAttribute

Att XAttribute kasta till en Nullable<T> av Int64.

Returer

En Nullable<T> av Int64 dessa innehåller innehållet i den här XAttribute.

Attribut

Undantag

Attributet innehåller inget giltigt Int64 värde.

Exempel

I följande exempel skapas ett attribut med långt heltalsinnehåll. Det hämtar sedan värdet genom att gjuta till av 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"))

Det här exemplet genererar följande utdata:

Nullable long: value=9223372036854775807

Se även

Gäller för

Explicit(XAttribute to Nullable<Single>)

Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs

Viktigt!

Detta API uppfyller inte CLS.

Omvandla värdet för detta XAttribute till en Nullable<T> av 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)

Parametrar

attribute
XAttribute

Att XAttribute kasta till Nullable<T> av Single.

Returer

En Nullable<T> av Single dessa innehåller innehållet i den här XAttribute.

Attribut

Undantag

Attributet innehåller inget giltigt Single värde.

Exempel

I följande exempel skapas ett attribut med flyttalsinnehåll med enkel precision. Det hämtar sedan värdet genom att gjuta till av 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"))

Det här exemplet genererar följande utdata:

Nullable Single: value=3.402823E+38

Se även

Gäller för

Explicit(XAttribute to Nullable<TimeSpan>)

Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs

Viktigt!

Detta API uppfyller inte CLS.

Omvandla värdet för detta XAttribute till en Nullable<T> av 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)

Parametrar

attribute
XAttribute

Att XAttribute kasta till en Nullable<T> av TimeSpan.

Returer

En Nullable<T> av TimeSpan dessa innehåller innehållet i den här XAttribute.

Attribut

Undantag

Attributet innehåller inget giltigt TimeSpan värde.

Exempel

I följande exempel skapas ett attribut med tidsintervallinnehåll. Det hämtar sedan värdet genom att gjuta till av 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"))

Det här exemplet genererar följande utdata:

Nullable TimeSpan: value=01:05:30

Kommentarer

Värdeutrymmet för ett attribut eller element som innehåller tidsintervallinnehåll är nära relaterat till varaktighetsinnehåll enligt beskrivningen i ISO 8601. När du skapar ett attribut eller element som innehåller tidsintervallsinnehåll formateras attribut- eller elementvärdena enligt W3C-specifikationen. Mer information finns i W3C-specifikationen.

Beteendet är slappt vid gjutning till ett Nullable<T> av TimeSpan från ett attribut eller element. Även om attributet eller elementvärdet inte är exakt formaterat enligt W3C-specifikationen konverteras värdet korrekt till en Nullable<T> av TimeSpan.

Se även

Gäller för

Explicit(XAttribute to Nullable<UInt32>)

Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs

Viktigt!

Detta API uppfyller inte CLS.

Omvandla värdet för detta XAttribute till en Nullable<T> av 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)

Parametrar

attribute
XAttribute

Att XAttribute kasta till en Nullable<T> av UInt32.

Returer

En Nullable<T> av UInt32 dessa innehåller innehållet i den här XAttribute.

Attribut

Undantag

Attributet innehåller inget giltigt UInt32 värde.

Exempel

I följande exempel skapas ett attribut med osignerat heltalsinnehåll. Det hämtar sedan värdet genom att gjuta till av 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"))

Det här exemplet genererar följande utdata:

Nullable uint: value=4294967295

Se även

Gäller för

Explicit(XAttribute to Nullable<UInt64>)

Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs

Viktigt!

Detta API uppfyller inte CLS.

Omvandla värdet för detta XAttribute till en Nullable<T> av 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)

Parametrar

attribute
XAttribute

Att XAttribute kasta till en Nullable<T> av UInt64.

Returer

En Nullable<T> av UInt64 dessa innehåller innehållet i den här XAttribute.

Attribut

Undantag

Attributet innehåller inget giltigt UInt64 värde.

Exempel

I följande exempel skapas ett attribut med osignerat långt heltalsinnehåll. Det hämtar sedan värdet genom att gjuta till av 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"))

Det här exemplet genererar följande utdata:

Nullable ulong: value=9223372036854775807

Se även

Gäller för

Explicit(XAttribute to TimeSpan)

Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs

Viktigt!

Detta API uppfyller inte CLS.

Omvandla värdet för detta XAttribute till en 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

Parametrar

attribute
XAttribute

Att XAttribute kasta till TimeSpan.

Returer

En TimeSpan som innehåller innehållet i den här XAttribute.

Attribut

Undantag

Attributet innehåller inget giltigt TimeSpan värde.

Parametern attribute är null.

Exempel

I följande exempel skapas ett attribut med tidsintervallinnehåll. Det hämtar sedan värdet genom att gjuta till 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)

Det här exemplet genererar följande utdata:

value=01:05:30

Kommentarer

Värdeutrymmet för ett attribut eller element som innehåller tidsintervallinnehåll är nära relaterat till varaktighetsinnehåll enligt beskrivningen i ISO 8601. När du skapar ett attribut eller element som innehåller tidsintervallsinnehåll formateras attribut- eller elementvärdena enligt W3C-specifikationen. Mer information finns i W3C-specifikationen.

Beteendet är släpphänt vid gjutning till ett TimeSpan från ett attribut eller element. Även om attributet eller elementvärdet inte formateras exakt enligt W3C-specifikationen konverteras värdet korrekt till en TimeSpan.

Se även

Gäller för

Explicit(XAttribute to String)

Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs

Viktigt!

Detta API uppfyller inte CLS.

Omvandla värdet för detta XAttribute till en 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

Parametrar

attribute
XAttribute

Att XAttribute kasta till String.

Returer

En String som innehåller innehållet i den här XAttribute.

Attribut

Exempel

I följande exempel skapas ett attribut med stränginnehåll. Det hämtar sedan värdet genom att gjuta till 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)

Det här exemplet genererar följande utdata:

(string)att=attribute content

Se även

Gäller för

Explicit(XAttribute to Nullable<Int32>)

Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs

Viktigt!

Detta API uppfyller inte CLS.

Omvandla värdet för detta XAttribute till en Nullable<T> av 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)

Parametrar

attribute
XAttribute

Att XAttribute kasta till en Nullable<T> av Int32.

Returer

En Nullable<T> av Int32 dessa innehåller innehållet i den här XAttribute.

Attribut

Exempel

I följande exempel skapas ett attribut med heltalsinnehåll. Det hämtar sedan värdet genom att gjuta till av 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"))

Det här exemplet genererar följande utdata:

Nullable int: value=2147483647

Se även

Gäller för

Explicit(XAttribute to UInt32)

Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs

Viktigt!

Detta API uppfyller inte CLS.

Omvandla värdet för detta XAttribute till en 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

Parametrar

attribute
XAttribute

Att XAttribute kasta till UInt32.

Returer

En UInt32 som innehåller innehållet i den här XAttribute.

Attribut

Undantag

Attributet innehåller inget giltigt UInt32 värde.

Parametern attribute är null.

Exempel

I följande exempel skapas ett attribut med osignerat heltalsinnehåll. Det hämtar sedan värdet genom att gjuta till 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)

Det här exemplet genererar följande utdata:

value=4294967295

Se även

Gäller för

Explicit(XAttribute to UInt64)

Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs

Viktigt!

Detta API uppfyller inte CLS.

Omvandla värdet för detta XAttribute till en 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

Parametrar

attribute
XAttribute

Att XAttribute kasta till UInt64.

Returer

En UInt64 som innehåller innehållet i den här XAttribute.

Attribut

Undantag

Attributet innehåller inget giltigt UInt64 värde.

Parametern attribute är null.

Exempel

I följande exempel skapas ett attribut med osignerat långt heltalsinnehåll. Det hämtar sedan värdet genom att gjuta till 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)

Det här exemplet genererar följande utdata:

value=1844674407370955161

Se även

Gäller för

Explicit(XAttribute to Single)

Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs

Viktigt!

Detta API uppfyller inte CLS.

Omvandla värdet för detta XAttribute till en 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

Parametrar

attribute
XAttribute

Att XAttribute kasta till Single.

Returer

En Single som innehåller innehållet i den här XAttribute.

Attribut

Undantag

Attributet innehåller inget giltigt Single värde.

Parametern attribute är null.

Exempel

I följande exempel skapas ett attribut med flyttalsinnehåll med enkel precision. Det hämtar sedan värdet genom att gjuta till 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)

Det här exemplet genererar följande utdata:

value=3.402823E+38

Se även

Gäller för

Explicit(XAttribute to Nullable<Guid>)

Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs

Viktigt!

Detta API uppfyller inte CLS.

Omvandla värdet för detta XAttribute till en Nullable<T> av 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)

Parametrar

attribute
XAttribute

Att XAttribute kasta till en Nullable<T> av Guid.

Returer

En Nullable<T> av Guid dessa innehåller innehållet i den här XAttribute.

Attribut

Undantag

Attributet innehåller inget giltigt Guid värde.

Exempel

I följande exempel skapas ett attribut med guid-innehåll. Det hämtar sedan värdet genom att gjuta till av 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"))

Det här exemplet genererar följande utdata:

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

Se även

Gäller för

Explicit(XAttribute to Nullable<Decimal>)

Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs

Viktigt!

Detta API uppfyller inte CLS.

Omvandla värdet för detta XAttribute till en Nullable<T> av 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)

Parametrar

attribute
XAttribute

Att XAttribute kasta till Nullable<T> av Decimal.

Returer

En Nullable<T> av Decimal dessa innehåller innehållet i den här XAttribute.

Attribut

Undantag

Attributet innehåller inget giltigt Decimal värde.

Exempel

I följande exempel skapas ett attribut med decimalinnehåll. Det hämtar sedan värdet genom att gjuta till av 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"))

Det här exemplet genererar följande utdata:

Nullable decimal: value=79228162514264337593543950335

Se även

Gäller för

Explicit(XAttribute to Decimal)

Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs

Viktigt!

Detta API uppfyller inte CLS.

Omvandla värdet för detta XAttribute till en 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

Parametrar

attribute
XAttribute

Att XAttribute kasta till Decimal.

Returer

En Decimal som innehåller innehållet i den här XAttribute.

Attribut

Undantag

Attributet innehåller inget giltigt Decimal värde.

Parametern attribute är null.

Exempel

I följande exempel skapas ett attribut med ett decimalvärde. Sedan hämtar den värdet för attributet genom att gjuta till 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)

Det här exemplet genererar följande utdata:

value=79228162514264337593543950335

Se även

Gäller för

Explicit(XAttribute to Nullable<DateTimeOffset>)

Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs

Viktigt!

Detta API uppfyller inte CLS.

Omvandla värdet för detta XAttribute till en Nullable<T> av 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)

Parametrar

attribute
XAttribute

Att XAttribute kasta till en Nullable<T> av DateTimeOffset.

Returer

En Nullable<T> av DateTimeOffset dessa innehåller innehållet i den här XAttribute.

Attribut

Undantag

Attributet innehåller inget giltigt DateTimeOffset värde.

Exempel

I följande exempel skapas ett attribut med datum och tid som innehåll. Det hämtar sedan värdet genom att gjuta till av 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"))

Det här exemplet genererar följande utdata:

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

Kommentarer

Den här konverteringsoperatorn XmlConvert använder klassen för att utföra konverteringen.

Gäller för

Explicit(XAttribute to Nullable<DateTime>)

Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs

Viktigt!

Detta API uppfyller inte CLS.

Omvandla värdet för detta XAttribute till en Nullable<T> av 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)

Parametrar

attribute
XAttribute

Att XAttribute kasta till en Nullable<T> av DateTime.

Returer

En Nullable<T> av DateTime dessa innehåller innehållet i den här XAttribute.

Attribut

Undantag

Attributet innehåller inget giltigt DateTime värde.

Exempel

I följande exempel skapas ett attribut med datum och tid som innehåll. Det hämtar sedan värdet genom att gjuta till av 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"))

Det här exemplet genererar följande utdata:

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

Kommentarer

Värdeutrymmet för ett attribut eller element som innehåller datum- och tidsinnehåll är nära relaterat till de datum och tider som beskrivs i ISO 8601. När du skapar ett attribut eller element som innehåller datum- och tidsinnehåll formateras attribut- eller elementvärdena enligt W3C-specifikationen. Mer information finns i W3C-specifikationen.

Beteendet är slappt vid gjutning till ett Nullable<T> av DateTime från ett attribut eller element. Även om attributet eller elementvärdet inte är exakt formaterat enligt W3C-specifikationen konverteras värdet korrekt till en Nullable<T> av DateTime.

Den här konverteringsoperatorn använder CultureInfo.InvariantCulture för att konvertera från en DateTime.

Se även

Gäller för

Explicit(XAttribute to Nullable<Boolean>)

Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs

Viktigt!

Detta API uppfyller inte CLS.

Omvandla värdet för detta XAttribute till en Nullable<T> av 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)

Parametrar

attribute
XAttribute

Att XAttribute kasta till Nullable<T> av Boolean.

Returer

En Nullable<T> av Boolean dessa innehåller innehållet i den här XAttribute.

Attribut

Undantag

Attributet innehåller inget giltigt Boolean värde.

Exempel

I följande exempel skapas ett attribut med booleskt innehåll. Det hämtar sedan värdet genom att gjuta till av 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)

Det här exemplet genererar följande utdata:

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

Kommentarer

När du konverterar till Boolean från ett attribut eller element är tillåtna värden "0", "1" och alla strängar som ger "true" eller "false" efter trimning och konvertering till gemener.

Se även

Gäller för

Explicit(XAttribute to Int64)

Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs

Viktigt!

Detta API uppfyller inte CLS.

Omvandla värdet för detta XAttribute till en 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

Parametrar

attribute
XAttribute

Att XAttribute kasta till Int64.

Returer

En Int64 som innehåller innehållet i den här XAttribute.

Attribut

Undantag

Attributet innehåller inget giltigt Int64 värde.

Parametern attribute är null.

Exempel

I följande exempel skapas ett attribut med ett långt heltal som innehåll. Sedan hämtar den värdet för attributet genom att gjuta till 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)

Det här exemplet genererar följande utdata:

value=9223372036854775807

Se även

Gäller för

Explicit(XAttribute to Int32)

Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs

Viktigt!

Detta API uppfyller inte CLS.

Omvandla värdet för detta XAttribute till en 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

Parametrar

attribute
XAttribute

Att XAttribute kasta till Int32.

Returer

En Int32 som innehåller innehållet i den här XAttribute.

Attribut

Undantag

Attributet innehåller inget giltigt Int32 värde.

Parametern attribute är null.

Exempel

I följande exempel skapas ett attribut med ett heltal som innehåll. Det hämtar sedan värdet genom att gjuta till 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)

Det här exemplet genererar följande utdata:

value=2147483647

Se även

Gäller för

Explicit(XAttribute to Guid)

Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs

Viktigt!

Detta API uppfyller inte CLS.

Omvandla värdet för detta XAttribute till en 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

Parametrar

attribute
XAttribute

Att XAttribute kasta till Guid.

Returer

En Guid som innehåller innehållet i den här XAttribute.

Attribut

Undantag

Attributet innehåller inget giltigt Guid värde.

Parametern attribute är null.

Exempel

I följande exempel skapas ett attribut med ett GUID som innehåll. Det hämtar sedan värdet genom att gjuta till 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)

Det här exemplet genererar följande utdata:

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

Se även

Gäller för

Explicit(XAttribute to Double)

Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs

Viktigt!

Detta API uppfyller inte CLS.

Omvandla värdet för detta XAttribute till en 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

Parametrar

attribute
XAttribute

Att XAttribute kasta till Double.

Returer

En Double som innehåller innehållet i den här XAttribute.

Attribut

Undantag

Attributet innehåller inget giltigt Double värde.

Parametern attribute är null.

Exempel

I följande exempel skapas ett attribut med Double innehåll. Det hämtar sedan värdet genom att gjuta till 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)

Det här exemplet genererar följande utdata:

value=1.79769313486231E+308

Se även

Gäller för

Explicit(XAttribute to Nullable<Double>)

Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs

Viktigt!

Detta API uppfyller inte CLS.

Omvandla värdet för detta XAttribute till en Nullable<T> av 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)

Parametrar

attribute
XAttribute

Att XAttribute kasta till Nullable<T> av Double.

Returer

En Nullable<T> av Double dessa innehåller innehållet i den här XAttribute.

Attribut

Undantag

Attributet innehåller inget giltigt Double värde.

Exempel

I följande exempel skapas ett attribut med flyttal med dubbel precision. Det hämtar sedan värdet genom att gjuta till av 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"))

Det här exemplet genererar följande utdata:

Nullable double: value=1.79769313486231E+308

Se även

Gäller för

Explicit(XAttribute to DateTimeOffset)

Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs

Viktigt!

Detta API uppfyller inte CLS.

Omvandla värdet för detta XAttribute till en 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

Parametrar

attribute
XAttribute

Att XAttribute kasta till DateTimeOffset.

Returer

En DateTimeOffset som innehåller innehållet i den här XAttribute.

Attribut

Undantag

Attributet innehåller inget giltigt DateTimeOffset värde.

Parametern attribute är null.

Exempel

I följande exempel skapas ett attribut med datum- och tidsinnehåll. Sedan omvandlas den till DateTimeOffset för att hämta värdet.

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)

Det här exemplet genererar följande utdata:

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

Kommentarer

Den här konverteringsoperatorn XmlConvert använder klassen för att utföra konverteringen.

Se även

Gäller för

Explicit(XAttribute to DateTime)

Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs

Viktigt!

Detta API uppfyller inte CLS.

Omvandla värdet för detta XAttribute till en 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

Parametrar

attribute
XAttribute

Att XAttribute kasta till DateTime.

Returer

En DateTime som innehåller innehållet i den här XAttribute.

Attribut

Undantag

Attributet innehåller inget giltigt DateTime värde.

Parametern attribute är null.

Exempel

I följande exempel skapas ett attribut med datum- och tidsinnehåll. Sedan omvandlas den till DateTime för att hämta värdet.

// 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)

Det här exemplet genererar följande utdata:

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

Kommentarer

Värdeutrymmet för ett attribut eller element som innehåller datum- och tidsinnehåll är nära relaterat till de datum och tider som beskrivs i ISO 8601. När du skapar ett attribut eller element som innehåller datum- och tidsinnehåll formateras attribut- eller elementvärdena enligt W3C-specifikationen. Mer information finns i W3C-specifikationen.

Beteendet är släpphänt vid gjutning till ett DateTime från ett attribut eller element. Även om attributet eller elementvärdet inte formateras exakt enligt W3C-specifikationen konverteras värdet korrekt till en DateTime.

Den här konverteringsoperatorn använder CultureInfo.InvariantCulture för att konvertera från en DateTime.

Se även

Gäller för

Explicit(XAttribute to Boolean)

Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs
Källa:
XAttribute.cs

Viktigt!

Detta API uppfyller inte CLS.

Omvandla värdet för detta XAttribute till en 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

Parametrar

attribute
XAttribute

Att XAttribute kasta till Boolean.

Returer

En Boolean som innehåller innehållet i den här XAttribute.

Attribut

Undantag

Attributet innehåller inget giltigt Boolean värde.

Parametern attribute är null.

Exempel

I följande exempel skapas ett attribut med ett Boolean värde och sedan omvandlas det till 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)

Det här exemplet genererar följande utdata:

(bool)BoolValue=True

Kommentarer

När du konverterar till Boolean från ett attribut eller element är tillåtna värden "0", "1" och alla strängar som ger "true" eller "false" efter trimning och konvertering till gemener.

Se även

Gäller för