Creando Objetos en C#

Page 25

How to Overload a Constructor ď Ž

Create multiple constructors that have the same name but different signatures ď Ź

Specify an initializer with this

public public class class Lion Lion {{ private name; private string string name; private age; private int int age;

}}

public public Lion() Lion() :: this( this( "unknown", "unknown", 00 )) {{ Console.WriteLine("Default: Console.WriteLine("Default: {0}", {0}", name); name); }} public public Lion( Lion( string string theName, theName, int int theAge theAge )) {{ name name == theName; theName; age age == theAge; theAge; Console.WriteLine("Specified: Console.WriteLine("Specified: {0}", {0}", name); name); }}


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.