I'm not big on the c# vocabulary, so I might be misinterpreting you.
But if I am correct, I don't think your example is very useful to show the working of parametrized and copy constructors.
So here's another one:
Now when you would type:Code:using System; using System.Collections.Generic; using System.Text; namespace TestConstructor { class MyCustomClass { public MyCustomClass() { Console.WriteLine("I am the default constructor"); } public MyCustomClass(string Parameter1) { Console.WriteLine("I am a copy constructor with the given parameter: " + Parameter1); } public MyCustomClass(int Parameter2) { Console.WriteLine("You can make as many copies as you like, though using different types; here's an integer: " + Parameter2); } /*public MyCustomClass(string Parameter3) { Console.WriteLine("This one would probably not compile because you already have used a string parameter alone."); }*/ public MyCustomClass(string Parameter4, int Parameter5) { Console.WriteLine("But this would work again: " + Parameter4 + Parameter5); } } }
You would get a list of overloads (copy constructors?) showing the different parameter combinations.Code:MyCustomClass = new MyCustomClass(
The use of this is that you can initialize your custom classes with dynamic values.
Hope this helps.




Reply With Quote