Cannot convert type 'string' to 'ushort'

M

Marcelo Muzilli

Howdy all,

in my program, I have a ushort variable and a string variable and if I
try to compile it, I'm receiving this error message: "Cannot convert
type 'string' to 'ushort'".

How can I compare both?

Example:

if ( uVariable != sVariable ) { ... }

Tia,

Marcelo Muzilli
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,


There is no implicit conversion between the two types. either you convert
the string to number or the number to string:

ushortvar.ToString == stringVar

or

Convert.ToUnit16( stringVar ) == ushortvar
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top