G
gazza67
I wonder if someone could tell me how to do what i am trying. Basically
I have a class pointed to by an object type variable which will point
to a class to be set at runtime. I want to call methods from the class
that the object var is pointing to but dont know how to go about it.
Cheers
Gary
using System;
namespace carsCarsCars
{
class MainClass
{
public static void Main(string[] args)
{
Console.WriteLine("Hello World!");
Toyota xyz794 = new Toyota();
Toyota xyz795 = new Toyota();
Nissan ttt214 = new Nissan();
Toyota tyz794 = new Toyota();
Person George = new Person("George", xyz794, xyz795);
Person Albert = new Person("Albert", ttt214, tyz794);
// -----------------------------------------------------
// George.carOne.printMake(); // this line doesnt compile
// ------------------------------------------------------
}
}
public class Person
{
string name;
public object carOne = new object();
public object carTwo = new object();
public Person(string theName, object theCarOne, object theCarTwo)
{
name = theName;
carOne = theCarOne;
carTwo = theCarTwo;
}
}
class Car
{
public int numberOfWheels=4;
}
class Toyota : Car
{
public void printMake() {
Console.WriteLine("toyota");
}
}
class Nissan : Car
{
public void printMake() {
Console.WriteLine("nissan");
}
}
}
I have a class pointed to by an object type variable which will point
to a class to be set at runtime. I want to call methods from the class
that the object var is pointing to but dont know how to go about it.
Cheers
Gary
using System;
namespace carsCarsCars
{
class MainClass
{
public static void Main(string[] args)
{
Console.WriteLine("Hello World!");
Toyota xyz794 = new Toyota();
Toyota xyz795 = new Toyota();
Nissan ttt214 = new Nissan();
Toyota tyz794 = new Toyota();
Person George = new Person("George", xyz794, xyz795);
Person Albert = new Person("Albert", ttt214, tyz794);
// -----------------------------------------------------
// George.carOne.printMake(); // this line doesnt compile
// ------------------------------------------------------
}
}
public class Person
{
string name;
public object carOne = new object();
public object carTwo = new object();
public Person(string theName, object theCarOne, object theCarTwo)
{
name = theName;
carOne = theCarOne;
carTwo = theCarTwo;
}
}
class Car
{
public int numberOfWheels=4;
}
class Toyota : Car
{
public void printMake() {
Console.WriteLine("toyota");
}
}
class Nissan : Car
{
public void printMake() {
Console.WriteLine("nissan");
}
}
}