Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 7th, 2008, 07:44 AM
Registered User
 
Join Date: Jan 2008
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default as,in and reference types error msg.....

hi....

i am using a method like this....


public static double setDefaultDoubleValue(string txtval)
{
 double dtxtval = txtval as double;
 return (dtxtval is double ? dtxtval : 0.00);
}

on compiling i m getiing the error message like "use reference types rather than value type"...i tried....

System.Double in place of double bt the prob is same....

can anyone help me clearing this thing....
thnx in advance...

  #2 (permalink)  
Old January 7th, 2008, 07:53 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

System.Double is a value type, and cannot be null (i.e. double d = null; is not valid).

The "as" keyword is used to try to store an object from one reference type to another. It returns null if the object is not of the correct type.
The "is" keyword returns true if the above transfer would work.

What you probably want to use is Double.TryParse(object, ref double);

public static double setDefaultDoubleValue(string textValue)
{
 double d;
 return double.TryParse(textValue, ref d) ? d : 0.00;
}


/- Sam Judson : Wrox Technical Editor -/
  #3 (permalink)  
Old January 8th, 2008, 07:14 AM
Registered User
 
Join Date: Jan 2008
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by samjudson
 System.Double is a value type, and cannot be null (i.e. double d = null; is not valid).

The "as" keyword is used to try to store an object from one reference type to another. It returns null if the object is not of the correct type.
The "is" keyword returns true if the above transfer would work.

What you probably want to use is Double.TryParse(object, ref double);

public static double setDefaultDoubleValue(string textValue)
{
double d;
return double.TryParse(textValue, ref d) ? d : 0.00;
}


/- Sam Judson : Wrox Technical Editor -/

coool.....
thanks for the support...

 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
error msg almotions ASP.NET 2.0 Basics 3 February 12th, 2008 08:34 AM
Error msg 3021 MathLearner VB Databases Basics 1 May 17th, 2007 07:41 AM
error msg aspsuraj BOOK: Wrox's ASP.NET 2.0 Visual Web Developer 2005 Express Edition Starter ISBN: 978-0-7645-8807-5 1 November 27th, 2006 08:30 PM
Breakpoint Error Msg Louisa VB.NET 2002/2003 Basics 1 March 29th, 2004 06:42 AM
Passing Reference Types by Value semiloof VS.NET 2002/2003 1 December 22nd, 2003 12:16 AM



All times are GMT -4. The time now is 08:25 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.