Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 7th, 2008, 07:44 AM
Registered User
 
Join Date: Jan 2008
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...

 
Old January 7th, 2008, 07:53 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
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 -/
 
Old January 8th, 2008, 07:14 AM
Registered User
 
Join Date: Jan 2008
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...






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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.