So Im learning basic C# and wonders how I can return x and y from AGE(); and NUMBER(); and use those variables in Name();
Right now x and y in the Name(); parameters are understandably wrong since there are no local variables in the constructor. But I returned x and y from the function. So how can I use them in the Name function?
namespace CSharp_001
{
class Program
{
public Program()
{
Name(x, y);
AGE();
NUMBER();
}
public int AGE()
{
int x;
Console.WriteLine(" And enter age: ");
x = Console.Read();
return x;
}
public int NUMBER()
{
int y;
Console.WriteLine(" And favorite number: ");
y = Console.Read();
return y;
}
public void Name(int x, int y)
{
Console.WriteLine("Enter your name: ");
string test = Console.ReadLine();
Console.WriteLine("Hi " + test);
}
static void Main(string[] args)
{
new Program();
Console.ReadLine();
}
}
}
xoryin theNamemethod, so why bother passing them in?Console.Readis the wrong function!