PC Review


Reply
Thread Tools Rate Thread

Cannot convert type 'string' to 'ushort'

 
 
Marcelo Muzilli
Guest
Posts: n/a
 
      13th Jun 2006
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
 
Reply With Quote
 
 
 
 
Greg Young
Guest
Posts: n/a
 
      13th Jun 2006
try using

ushort tmp = ushort.Parse(yourstring) ;
if(YourUShort != tmp) { }

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung

"Marcelo Muzilli" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> 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



 
Reply With Quote
 
Ignacio Machin \( .NET/ C# MVP \)
Guest
Posts: n/a
 
      13th Jun 2006
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


--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


"Marcelo Muzilli" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> 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



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert string-type to a real type. Mr. X. Microsoft C# .NET 7 4th Sep 2010 03:35 PM
Is there a way to convert a string representation of a type name into a Type object? Deckarep Microsoft C# .NET 6 18th Jun 2007 03:55 AM
convert type string to type guid guoqi zheng Microsoft ASP .NET 1 2nd Jul 2005 03:44 PM
Connection String object Convert to String Variable Type =?Utf-8?B?TWlrZSBNb29yZQ==?= Microsoft ASP .NET 2 26th Oct 2004 03:43 PM
convert datetime type to string type in a dataset? tom Microsoft ADO .NET 1 10th Dec 2003 08:28 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:02 AM.