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
ahmed sami
NA
64
200.8k
what's the wrong with my code ?
Mar 19 2013 1:18 PM
the output of this program is
count = 1
count = 1
count = 1
and it suppose to be :
count = 1
count = 2
count = 3
what's the wrong with my code ?
or how can i get the output 1,2,3
class Employee
{
int id;
string name;
double salary;
int objectCount;
public int count
{
get { return objectCount; }
}
public int ID
{
get { return id; }
set
{
if (value > 1000)
this.id = value;
else
this.id = 1000;
}
}
public string NAME
{
get { return name; }
set
{
if (value.Length != 0)
this.name = value;
else
this.name = "unknown";
}
}
public double SALARY
{
get { return salary; }
set
{
if (value > 0)
this.salary = value;
else
{
this.salary = 0;
Console.WriteLine("Wrong Salary Value .. !!");
}
}
}
public Employee()
{
this.id = 1000;
this.name = "";
this.salary = 0;
objectCount++;
}
public Employee(int x, string y, double z)
{
ID = x;
NAME = y;
SALARY = z;
objectCount++;
}
public void Allowance(double x)
{
if (x > 0)
this.salary += x;
else
Console.WriteLine("Invalied Allowance");
}
public void Dedicate(double x)
{
if (x > 0)
this.salary -= x;
else
Console.WriteLine("Invalied Dedicate");
}
public string EmployeeToString()
{
return string.Format("id : {0}\nname : {1}\nsalary : {2}", id, name, salary);
}
~Employee()
{
objectCount--;
}
}
Employee emp1 = new Employee(1200, "A.matter", 900);
Employee emp2 = new Employee(1400, "A.bader", 1100);
Employee emp3 = new Employee();
Console.WriteLine("count = {0}",emp1.count);
Console.WriteLine("count = {0}",emp2.count);
Console.WriteLine("count = {0}",emp3.count);
Console.ReadKey();
Reply
Answers (
1
)
how to get the serial no. and logging on date time of every
Converting to VS2012 C#-ASP.NET 4.5 from 2000 and older.