Answered by:
Constructor examples

Question
-
Hello there, I need to write a short presentation for my programming class and I need some help. I found some of the constructor examples on the web, but they does not seem to work for me. I am using C# Console Application project. I got the examples here: http://www.onlinebuff.com/article_what-is-a-constructor-in-c-and-list-types-of-constructors-in-c_19.html ; I am having trouble with the "Copy Constructor", not sure how it works, because the code I use from this website is not working - the console is blank, not showing any information at all. Any help would be appreciated. :)
Answers
-
The program is terminating before you can see results. Simply add a readline at end of program like below.
static void Main(string[] args) { Car obj1 = new Car("BMW Sedan", 4545, 5000000); Car obj2 = new Car(obj1); Console.WriteLine("Car Name : {0}", obj2._nameofcar); Console.WriteLine("Car Number : {0}", obj2._carno); Console.WriteLine("Car Price : {0}", obj2._carprice); Console.ReadLine(); }
jdweng
All replies
-
The program is terminating before you can see results. Simply add a readline at end of program like below.
static void Main(string[] args) { Car obj1 = new Car("BMW Sedan", 4545, 5000000); Car obj2 = new Car(obj1); Console.WriteLine("Car Name : {0}", obj2._nameofcar); Console.WriteLine("Car Number : {0}", obj2._carno); Console.WriteLine("Car Price : {0}", obj2._carprice); Console.ReadLine(); }
jdweng
-
-