namespace Tutorial1
{
class Program
{
static int AddNumbers(int number1, int number2)
{//Note that we declare with the variable in our method and only use the name assigned
int result;//this is to make it more clear what we're returning
result = number1 + number2;
return result;
}
static int GetMedian(int number)
{
return (number/2);//Here we're returning number back in half.
/*we could also have done it like this
int finishedproduct;
finishedproduct = number/2;
return finishedproduct;
*/
}
static int GetNumbers()
{//This method accepts no arguments, it's just set to get the numbers and pass them back
string entry;
int entrytranslated;
Console.WriteLine("Please enter a number");
entry = Console.ReadLine();
Console.WriteLine();
entrytranslated = int.Parse(entry);
return entrytranslated;
}
static void Main(string[] args)//This is our entry point even if it's below everything else
{
int product;
int numberA, numberB;
numberA = GetNumbers();//Here you see that we're using the method to assign a variable to numberA
numberB = GetNumbers();//Again we're using GetNumber to assign a variable
product = AddNumbers(numberA,numberB);//Now we're using add number, feeding it it's required variables and
//it's assigning a number to product
Console.WriteLine("The sum of the numbers is " + product);//Here we're showing the product
product = GetMedian(product);//now product will be assigned the median using GetMedian
Console.WriteLine("The median of the two numbers is " + product);
Console.ReadLine();
}
}
}
Here is code so you could see what I am learning :P
"There is nothing either good or bad, but our thinking makes it so"
I'm pretty sure the return statement is just the same in C++... It's just returning your arguments, which is something I should revise on. I think I skipped a large part of the Functions chapter on my book... I'll get right on it
namespace Tutorial1
{
class Program
{
static int AddNumbers(int number1, int number2)
{//Note that we declare with the variable in our method and only use the name assigned
int result;//this is to make it more clear what we're returning
result = number1 + number2;
return result;
}
static int GetMedian(int number)
{
return (number/2);//Here we're returning number back in half.
/*we could also have done it like this
int finishedproduct;
finishedproduct = number/2;
return finishedproduct;
*/
}
static int GetNumbers()
{//This method accepts no arguments, it's just set to get the numbers and pass them back
string entry;
int entrytranslated;
Console.WriteLine("Please enter a number");
entry = Console.ReadLine();
Console.WriteLine();
entrytranslated = int.Parse(entry);
return entrytranslated;
}
static void Main(string[] args)//This is our entry point even if it's below everything else
{
int product;
int numberA, numberB;
numberA = GetNumbers();//Here you see that we're using the method to assign a variable to numberA
numberB = GetNumbers();//Again we're using GetNumber to assign a variable
product = AddNumbers(numberA,numberB);//Now we're using add number, feeding it it's required variables and
//it's assigning a number to product
Console.WriteLine("The sum of the numbers is " + product);//Here we're showing the product
product = GetMedian(product);//now product will be assigned the median using GetMedian
Console.WriteLine("The median of the two numbers is " + product);
Console.ReadLine();
}
}
}
Here is code so you could see what I am learning :P
namespace Tutorial1
{
class Program
{
static int AddNumbers(int number1, int number2)
{//Note that we declare with the variable in our method and only use the name assigned
int result;//this is to make it more clear what we're returning
result = number1 + number2;
return result;
}
static int GetMedian(int number)
{
return (number/2);//Here we're returning number back in half.
/*we could also have done it like this
int finishedproduct;
finishedproduct = number/2;
return finishedproduct;
*/
}
static int GetNumbers()
{//This method accepts no arguments, it's just set to get the numbers and pass them back
string entry;
int entrytranslated;
Console.WriteLine("Please enter a number");
entry = Console.ReadLine();
Console.WriteLine();
entrytranslated = int.Parse(entry);
return entrytranslated;
}
static void Main(string[] args)//This is our entry point even if it's below everything else
{
int product;
int numberA, numberB;
numberA = GetNumbers();//Here you see that we're using the method to assign a variable to numberA
numberB = GetNumbers();//Again we're using GetNumber to assign a variable
product = AddNumbers(numberA,numberB);//Now we're using add number, feeding it it's required variables and
//it's assigning a number to product
Console.WriteLine("The sum of the numbers is " + product);//Here we're showing the product
product = GetMedian(product);//now product will be assigned the median using GetMedian
Console.WriteLine("The median of the two numbers is " + product);
Console.ReadLine();
}
}
}
Here is code so you could see what I am learning :P
EdEown wrote:
I just cant understand what "return" means
When a function 'returns' something it is basically outputting it to the calling function. I don't know C# so I can't help you specifically with that but in C/++ you could have a function such as
W00t!
Finally finished the functions chapter of my book! As well as the pointers, references, classes and inheritance chapters in about 3 days. All I got left is polymorphism, macros and GUI programming.
I would explain to you what the return key word meant now means but it seems hurstshifter has already covered it.
Anyway sorry about the smart ass reply I gave earlier. I don't really respond like that, honest.
You can program in c# without using static although it can be very useful. For example if i want to make an object or variable global i would declare it as public static. But if your only starting i wouldn't worry about it too much, you'll understand it when you need to use it.