The new version of my famous C# Yellow Book is now available for download. This free 197 page book is the basis of our programming course and has a whole bunch of new content, along with reorganised layout and proper sections. Get yours today from here:
static double readValue ( string prompt, // prompt for the user double low, // lowest allowed value double high // highest allowed value ) { double result = 0; do { Console.WriteLine (prompt + " between " + low + " and " + high ); string resultString = Console.ReadLine (); result = double.Parse(resultString); } while ( (result < low) || (result > high) ); return result ; //why return result? why not return 0 or 1 or 999? The program does the same? }
Im new to c# programming and my doubt is that i dont understand one line: return result. I know it need the return because it is not a void method but why "result"? what's the difference if i use 0 or any other number? Thanks in advance.
Reader Comments (2)
string prompt, // prompt for the user
double low,
// lowest allowed value
double high
// highest allowed value
)
{
double result = 0;
do
{
Console.WriteLine (prompt +
" between " + low +
" and " + high );
string resultString = Console.ReadLine ();
result = double.Parse(resultString);
} while ( (result < low) || (result > high) );
return result ; //why return result? why not return 0 or 1 or 999? The program does the same?
}
Im new to c# programming and my doubt is that i dont understand one line: return result. I know it need the return because it is not a void method but why "result"? what's the difference if i use 0 or any other number? Thanks in advance.