Mega Code Archive

 
Categories / VB.Net / XML
 

Cast attribute value to nullable integer

Imports System Imports System.Xml Imports System.Xml.XPath Public Class MainClass     Public Shared Sub Main()         Dim root As XElement = <Root Att1="attribute 1 content" Att2="2"/>                  Dim c1 As String = CStr(root.Attribute("Att1"))         Console.WriteLine("c1:{0}", IIf(c1 Is Nothing, "attribute does not exist", c1))                  Dim c2 As Nullable(Of Integer) = CType(root.Attribute("Att2"), Nullable(Of Integer))         Console.WriteLine("c2:{0}", IIf(c2.HasValue, c2, "attribute does not exist"))              End Sub End Class