5 Replies - 785 Views - Last Post: 28 September 2009 - 03:40 PM Rate Topic: -----

#1 reginaleo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 28-September 09

visual c# basics

Posted 28 September 2009 - 03:30 PM

Convert.ToDouble(string); x1,x2,y1,y2,u1,u2,v1,v2;

i need some help converting from a string to an integer /double...i have a test to do tomorrow andi just started learnin c# yesterday
Is This A Good Question/Topic? 0
  • +

Replies To: visual c# basics

#2 Smurphy  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 35
  • View blog
  • Posts: 367
  • Joined: 07-July 08

Re: visual c# basics

Posted 28 September 2009 - 03:33 PM

We do not do your work for you. Read our rules and come back.
Was This Post Helpful? 0
  • +
  • -

#3 danny_kay1710  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 25
  • View blog
  • Posts: 350
  • Joined: 27-April 08

Re: visual c# basics

Posted 28 September 2009 - 03:33 PM

What exactly is x1, x2 etc for.

You have the correct code at the top although the syntax seems a bit strange:

double myNewDouble = Convert.ToDouble(string_to_convert_goes_here);
int myNewInt = Convert.ToInt32(string_to_convert_goes_here);



EDIT: @Smurphy: technically the correct code was in front of them in their own post before I posted, I just think the understanding is lacking.

This post has been edited by danny_kay1710: 28 September 2009 - 03:35 PM

Was This Post Helpful? 0
  • +
  • -

#4 reginaleo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 28-September 09

Re: visual c# basics

Posted 28 September 2009 - 03:39 PM

View PostSmurphy, on 28 Sep, 2009 - 02:33 PM, said:

We do not do your work for you. Read our rules and come back.



i kno i just need to know how to convert from a string to an integer thats all

View Postdanny_kay1710, on 28 Sep, 2009 - 02:33 PM, said:

What exactly is x1, x2 etc for.

You have the correct code at the top although the syntax seems a bit strange:

double myNewDouble = Convert.ToDouble(string_to_convert_goes_here);
int myNewInt = Convert.ToInt32(string_to_convert_goes_here);



EDIT: @Smurphy: technically the correct code was in front of them in their own post before I posted, I just think the understanding is lacking.


the x1 y1 stuff are all the things i have to convert to a double

View Postreginaleo, on 28 Sep, 2009 - 02:37 PM, said:

View PostSmurphy, on 28 Sep, 2009 - 02:33 PM, said:

We do not do your work for you. Read our rules and come back.



i kno i just need to know how to convert from a string to an integer thats all

View Postdanny_kay1710, on 28 Sep, 2009 - 02:33 PM, said:

What exactly is x1, x2 etc for.

You have the correct code at the top although the syntax seems a bit strange:

double myNewDouble = Convert.ToDouble(string_to_convert_goes_here);
int myNewInt = Convert.ToInt32(string_to_convert_goes_here);



EDIT: @Smurphy: technically the correct code was in front of them in their own post before I posted, I just think the understanding is lacking.


the x1 y1 stuff are all the things i have to convert to a double



i guess i should have them where i have string written then...ok thank you
Was This Post Helpful? 0
  • +
  • -

#5 danny_kay1710  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 25
  • View blog
  • Posts: 350
  • Joined: 27-April 08

Re: visual c# basics

Posted 28 September 2009 - 03:40 PM

View Postreginaleo, on 28 Sep, 2009 - 09:35 PM, said:

View PostSmurphy, on 28 Sep, 2009 - 02:33 PM, said:

We do not do your work for you. Read our rules and come back.



i kno i just need to know how to convert from a string to an integer thats all


DIC does have rules that state you have to make a best effort.

If you look at my first post which states you have put the correct code in your first post - plus with my slight reformat it should give you some hints on what you need to do. If x1, x2 etc where all the values you needed to change just letting you know you will need more than one line.
Was This Post Helpful? 0
  • +
  • -

#6 SixOfEleven  Icon User is offline

  • using Caffeine;
  • member icon

Reputation: 929
  • View blog
  • Posts: 6,316
  • Joined: 18-October 08

Re: visual c# basics

Posted 28 September 2009 - 03:40 PM

You will need a variable of the type that you want to convert. Then you would pass in the string you want to convert as an argument. There are three ways to convert strings to numbers.

The first is the one you posted:

double value = Convert.ToDouble(s);



That would convert the string s to a double.

Next there is the Parse method of the types.

double value = double.Parse(s);



Both of those are equivalent in that Convert calls the Parse method.

The third is a little more complicated but is safer in that if you pass an invalid argument your program will not throw an exception.

double result = 0;
bool conversionResult = double.TryParse(s, out result);



If TryParse succeeds it returns true. If it fails it returns false. So you could check to make sure the conversion was successful.

if (converstionResult)
	// Conversion worked!
else
	// Conversion failed!



Converting to an int is done the same way. You basically just change double to int

int value = int.Parse(s);
value = Convert.ToInt32(s);

int result = 0;
bool conversionResult = int.TryParse(s, out result);


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1