title: Option Strict and Unboxing Object to String
body: <p>I have a treeview where some of the treenodes have a string saved into their tag object and some of the tags are left as nothing. Later on I want to use the strings for something, in the nodes where they exist.</p>
  
  <pre><code>For Each tn As TreeNode In TreeView1.Nodes
      If Not String.IsNullOrWhiteSpace(tn.Tag) Then
          Call DoTagStringStuff(tn.Tag)
      End If
  Next tn
  </code></pre>
  
  <p>This worked fine until I needed to turn on option strict to make my code compatible with a co-workers project. I'm a bit confused about how to best unbox the string from the treenode.tag object.</p>
  
  <p>The error popup suggest using <code>CStr</code>, but I was under the impression that the <code>CStr</code> function was only in VB.net as a throwback to VB6, and really shouldn't be used for new code. If I try <code>tn.Tag.toString</code> in the above code, I get an error at runtime when it fails to compute <code>Nothing.toString</code>.</p>
  
  <p>What is the right way to fix this? Should I even be using the tag object to hold string values in the first place, or is there a better treenode property that wouldn't require unboxing I can use for this?</p>
  
  <p>Edit: I think perhaps this would be correct?</p>
  
  <pre><code>For Each tn As TreeNode In theNode.Nodes
      If tn.Tag IsNot Nothing Then
          Call DoTagStringStuff(DirectCast(tn.Tag, String))
      End If
  Next tn
  </code></pre>
  
  <p>Except I'm not checking for an empty or only whitespace string anymore.</p>