Reputation: 33
while trying to call base constructor it throw error like "object doesn't contain constructor that take one argument"
public string FirstName { get;private set; }
public string LastName { get;private set; }
public Employee(string firstName)
{
FirstName = firstName;
}
public Employee(string firstName,string lastName):base(firstName)//error
{
LastName = lastName;
}
public string SayHello()
{
return FirstName + " " + LastName;
}
thanks
Upvotes: 3
Views: 46
Reputation: 186803
You'd probably want to call current class constructor, not a base class constructor:
public Employee(string firstName, string lastName): this(firstName) // this, not base
{
LastName = lastName;
}
Upvotes: 8