Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / July 2007

Tip: Looking for answers? Try searching our database.

Convert textbox value to a short:

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
MarkusJNZ@gmail.com - 14 Jul 2007 23:02 GMT
Hi, I have a textbox in an asp.net app and all I want to do is store
the value of the textbox in a short if there is a value in the text
box;

I came up with the following (Where txtID is a asp.net textbox
control)

short ID = (txtID.Text != string.Empty ? short.Parse(txtID.Text) : 0);

But I get the following error

"Type of conditional expression cannot be determined because 'short'
and 'int' implicitly convert to one another"

I have tried

short ID = (txtID.Text != string.Empty ? Convert.ToInt16(txtID.Text) :
0);

and

short ID = (txtID.Text != string.Empty ? ((short)txtID.Text) : 0);

But still get errors

Any help appreciated!

Thanks
Markus
Göran Andersson - 15 Jul 2007 00:14 GMT
> Hi, I have a textbox in an asp.net app and all I want to do is store
> the value of the textbox in a short if there is a value in the text
[quoted text clipped - 25 lines]
> Thanks
> Markus

It's not the short value that is the problem, it's the zero. A numeric
literal (without a period) is of the type int, unless you specify otherwise.

Cast the literal to short: (short)0

Also: it's more efficient to check the length of the string than to make
a string comparison.

Signature

Göran Andersson
_____
http://www.guffa.com

MarkusJNZ@gmail.com - 15 Jul 2007 01:15 GMT
On Jul 15, 9:14 am, G?ran Andersson <gu...@guffa.com> wrote:
> Markus...@gmail.com wrote:
> > Hi, I have a textbox in an asp.net app and all I want to do is store
[quoted text clipped - 40 lines]
>
> - Show quoted text -

Thankyou G?ran
Regards
Markus

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.