Training
Module
Convert data types using casting and conversion techniques in C# - Training
Explore using C# techniques for casts and conversions.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
The majority of the methods found in an XmlConvert class are used to convert data between strings and strongly typed formats. Methods are locale independent. This means that they do not take into account any locale settings when doing conversion.
The following sample reads a string and converts it to a DateTime type.
Given the following XML input:
Input
<Element>2001-02-27T11:13:23</Element>
This code converts the string to the DateTime format:
reader.ReadStartElement()
Dim vDateTime As DateTime = XmlConvert.ToDateTime(reader.ReadString())
Console.WriteLine(vDateTime)
reader.ReadStartElement();
DateTime vDateTime = XmlConvert.ToDateTime(reader.ReadString());
Console.WriteLine(vDateTime);
The following sample reads an Int32 and converts it to a string.
Given the following XML input:
Input
<TestInt32>-2147483648</TestInt32>
This code converts the Int32 into a String:
Dim vInt32 As Int32 = -2147483648
writer.WriteElementString("TestInt32", XmlConvert.ToString(vInt32))
Int32 vInt32=-2147483648;
writer.WriteElementString("TestInt32",XmlConvert.ToString(vInt32));
.NET feedback
.NET is an open source project. Select a link to provide feedback:
Training
Module
Convert data types using casting and conversion techniques in C# - Training
Explore using C# techniques for casts and conversions.