what is difference betweent

Posted by Cnagasa under C# on 2/13/2012 | Points: 10 | Views : 1128 | Status : [Member] | Replies : 7
hi every one,


what is difference betweent Convert.ToDouble and Double.Parse


Regard's
Sudarshan

sudarshan.c


Responses

Posted by: Pradeepkumar417 on: 2/13/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,

Convert.ToDouble : You can convert any value to double by using this.
Double.Parse : You can convert only string representation of a number in a specified style by using this.

Thanks & Regards,
Software Engineer,
Pradeep Kumar

Cnagasa, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Cnagasa on: 2/13/2012 [Member] Starter | Points: 25

Up
0
Down
hi,

thanking u for given the reply can u send me the 1 Example

Regard's
Sudarshan.C

sudarshan.c

Cnagasa, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Pradeepkumar417 on: 2/13/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,

Try this below example

int i = 1;
double d = Convert.ToDouble(i);
string num = "4";
double d1 = Double.Parse(num);



Thanks & Regards,
Software Engineer,
Pradeep Kumar

Cnagasa, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Gow.net on: 2/13/2012 [Member] Starter | Points: 25

Up
0
Down


 int i = 1;

double d = Convert.ToDouble(i);
Console.WriteLine(d);
string num = "4";
double d1 = Double.Parse(num);

Console.WriteLine(d1);
string j = "1";
double f = Convert.ToDouble(j);

Console.WriteLine(f);

// Error
// int z = 1;
// double d2 = Double.Parse(z);
// Console.WriteLine(d2);


gowthaman8870226416

Cnagasa, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nvm on: 2/13/2012 [Member] Starter | Points: 25

Up
0
Down

HI Sudarshan,

Main Deference is,
Conver.ToDouble(Value) is capable to handle null values, But Double.Parse(Value) through exception.

Thank you
NVM

Cnagasa, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Naraayanan on: 2/13/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,
ConvertTo.Double returns 0 when nothing is passed, whereas Double. Parse
throws an exception.


Regards,
Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/
http://abaprocker.blogspot.com/

Cnagasa, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sabarimahesh on: 3/20/2012 [Member] Bronze | Points: 25

Up
0
Down
I wonder if somebody could explain me the difference between Double.Parse and Convert.ToDouble. If I'm not mistaken they are implemented differently (I though for a moment they might be the same like cint(anInt) and cType(anInt, System.Int32) but I checked with ildasm) - if I didn't made a mistake.
So when to use which syntax? Is there any performance penalty when using the one over the other or does anybody knows any differences?






I want to assign to a variable in my code and assignt this to that

variable.

double Number1= (double)Txt_Number1.text;


Error

I want to assign to a variable in my code and assignt this to that
variable.

double Number1= (double)Txt_Number1.text;


Life is a Race
Thanks & Regards
By
Sabari Mahesh P M

Cnagasa, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response