A A

A A

  • NA
  • 21
  • 11.9k

how can a user define your parameters

Oct 8 2013 8:47 PM
how can i send values that the user input, to my constructor in another class. because im trying to achieve this but i cant seem to get it.
for example

class car
{
public car(string x, int y)
{
console.write("This is your favorite car: " + x);// here i want to show the values the user input.
console.write("This is your favorite year: " +y);
}
class main
{
string x;
int y;
car brand = new car (x, y)//here i want the values that the user input to be sent to my constructor in the class car.
console.write("whats you favorite car: ");
brand.x = console.readline();//here i want the user to input any car he wants
console.write("what year is your favorite car: ");
brand.y = double.parse(console.readline());//here i want the user to input any year he wants

}


Answers (1)