TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Constructor Chaining in C#
Akshay Patel
Apr 24
2016
Code
1.3
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
namespace
ConstructorChaining
{
class
Employee
{
public
string
FirstName {
get
;
private
set
; }
public
string
LastName {
get
;
private
set
; }
public
Employee()
{
this
.FirstName =
"Akshay"
;
this
.LastName =
"Patel"
;
}
public
Employee(
string
firstName)
{
this
.FirstName = firstName;
}
public
Employee(
string
firstName,
string
lastName) :
this
(firstName)
{
this
.LastName = lastName;
}
}
}
Client:
namespace
ConstructorChaining
{
class
Program
{
static
void
Main(
string
[] args)
{
Employee emp2 =
new
Employee(
"Ishu"
,
"Patel"
);
Console.WriteLine(emp2.FirstName +
" "
+ emp2.LastName);
Console.ReadKey();
}
}
}
C#