calling a method

Posted 08 May 2010 - 10:33 AM

ok i have been racking my brain trying to figure this out..and for some reason i cant quite get it to display. I am writing a method to make a calculation and return a value inside an if statement to a label i already have set up for the display text.
This is the method i have set up to return the value of farenheit converted to celsius

Im new to C# this is my first class..and i had trouble when i was first starting vb too...so im hoping that it will be something simple that im overlooking or forgetting about. Any help is appreciated..thanks in advance

Re: calling a method

Posted 10 May 2010 - 10:53 AM

K first i did fix the algorithm for the conversion methods. and have tried a couple of calls with message box

MessageBox.Show(converttocelsius(convcelsius).ToString);

i could not get this to work gives me an error about converting method to string.
but i was just using the message box's to try and help me see if any part of it is working. I actually need to figure out how to call to a label i just dont understand the syntax of how to word it so i can call the method i have set up with return value. Is there a special way that you are supposed to set up the return..or call the return to a label?
still have it to pass the value of input temperature to the method for the conversion then return convcelsius/convfarenheit but how do you call convcelsius or convfarenheit

Re: calling a method

Posted 11 May 2010 - 09:54 AM

Psychocoder, no i didnt mean for it to seem like that. I had tried some stuff with how you had it built up but there were things that i didnt understand like the outc within the if statements. i figured that was something specific with messagebox's. but on that note thank you for showing me a better way of writing the methods that i had set up...cut's down only 1 line of code but good to know it can be set up inline setting variable and declaring it within the same line.

And on the issue of formatting the line

conversionlbl.Text = string.Format("{0:0}", converttocelsius(32));

i have learned only vb and am confused as to the way the last part of this strign is set up. I thought that anything that you put within "" will come out as text to wherever you have it set to display.
My other question in this line is the (32) what is this value for? my book is unclear my thinking is its the value your calling from that method. and if that is the case why 32 in this situation when the value will be changing on a regular?