Visual studio feeds

All Visual Studio blogs in one place


Enter your email address:

Delivered by FeedBurner

Increase your website traffic with



Anti-spam: How many eyes has a typical person?

Follow us on FB


VB Quark #5: C is for Char

AddThis Social Bookmark Button
Can you pick the problem with this code ? :       Dim currentChar As Char

      For i = 0 To largenumber
         currentChar = getChar(i)
         If currentChar = "a" Then
            count += 1
         End If
  The answer of course is the literal “a” is of type string, not of type Char. Hence currentChar gets implicitly widened to a String to make the expression a string comparison expression. This means a new string is created with the contents of currentChar on each iteration, and the comparison is a string comparison which checks for null strings and empty strings and then does a compare ordinal etc. This is incredibly inefficient. If “a” was typed as Char, then the comparison is a simple low level IL compare of the underlying values (int16’s). You can...(Read whole news on source site)

Home : Blog List : Bill's random thoughts... : VB Quark #5: C is for Char