Search code examples
stringvisual-studio-2013string-concatenation

Why am I getting an InvalidCastException here?


I'm trying to write code to print out "Row (0 to 3): ".

Here's my code:

ReadOnly gridSize As Integer = 4
Dim s1 As String
s1 = "Row (0 to " & (gridSize - 1) & "): "
WriteLine(s1)

I'm getting an InvalidCastException with the following error at the last line, when the machine tries to print out the string:

Conversion from string "Row (0 to 3): " to type 'Integer' is not valid.


Solution

  • Integer is not a String. How about using gridSize.ToString() ?