Hi,
I have static variable in my class.
I use get and set properties.
I do like below.
Does it make sense for this question?
My problem is object call in main(). Please help me out.
I have static variable in my class.
I use get and set properties.
I do like below.
Does it make sense for this question?
My problem is object call in main(). Please help me out.
Code:
namespace Employeer
{
public class employee
{
string name;
int salary;
public static int count=0;
public int stopcount=0;
public string Name()
{ get{ return name; }
set{
if( count>10)
{ name="can’t be instantiated more than 10 times";
count=0;
stopcount=1;
break;
}
else
{ name=value; }
}
}
}//______________end namespace_______________________
Code:
using Employeer;
public class company
{
public static void main()
{
employee e= new employee();
Console.WriteLine("Employee name:{0},Salary:{1}",e.Name,e.Salary);
Console.ReadLine();
if(e.stopcount!=1)
{
e.Name="Susan";
e.Salary=4000;
Console.WriteLine("Employee name:{0},Salary:{1}",e.Name,e.Salary);
Console.ReadLine();
}
else
{
Console.WriteLine("can’t be instantiated more than 10 times");
break;
}
}
}
Comment