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
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
ravindra agnihotri
NA
8
611
change in variable using constructor
Jan 23 2016 4:12 PM
what should i do so that value of variable "age" will become 0,if entered value of "age"<0 , by making changes only in constructor's body??
Class Person
{
public int age;
public Person(int initial_Age)
{
if (initial_Age < 0)
{
Console.WriteLine("This person is not valid, setting age to 0.");
}
}
static void Main(string[] args)
{
Console.WriteLine("enter age");
int age = int.Parse(Console.ReadLine());
Person p= new Person(age);
Console.WriteLine("Age={0}",age);
Console.ReadKey();
}
}
Reply
Answers (
2
)
Error in C# Procedure that compares 2 tables
import csv into excel without header