Friday, March 16, 2012

Option Strict on disallows implicit conversions from String to Char

Dim nameValuePairs As String() = decQS.Split("&")

I'm getting the following error:

Option Strict on disallows implicit conversions from 'String' to 'Char'

Does anyone know how I can resolve this in VB.NET?

ScAndalDim nameValuePairs As String() = decQS.Split("&"c)
Worked like a charm! What exactly is this? I have never seen that type of notation?

ScAndal
The following was taken from the SDK:


Appending the literal type character C to a single-character string literal forces it to the Char data type. This is required if the type checking switch (Option Strict) is on, as the following example shows:
Option Strict On
' ...
Dim CharVar As Char
CharVar = "Z" ' Cannot convert String to Char with Option Strict On.
CharVar = "Z"C ' Successfully assigns single character to CharVar.

0 comments:

Post a Comment