Primary constructors reduced declaration of various contructors with
diferent arguments. Primary constructors is declare on the type
declaration and this is why it so special. For example:
public
class
Person (
string
defaultName)
{
private
string
m_Name=defaultName;
public
string
Name {
get
;
set
;}
public
Person()
{
Name=defaultName;
}
}
We can define Primary Constructor in combination on Auto-Property Initializer on the following way:
public
class
Person (
string
defaultName)
{
private
string
m_Name=defaultName;
public
string
Name {
get
;
set
;}=defaultName
}
Posted
Oct 20 2014, 09:50 PM
by
Bahrudin