using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication9
{
class Program
{
static void Main(string[] args)
{
employee a = new employee();
employee b = new employee();
employee c = new employee();
employee.ShowConut();
}
class employee
{
public static int conut;
public employee()
: this("li", "1")
{
}
public employee(string n,string I)
{
Name = n;
ID1 = I;
conut += 1;
}
string name;
public string Name
{
get { return name; }
set { name = value; }
}
string ID;
public string ID1
{
get { return ID; }
set { ID = value; }
}
public void showname()
{
Console.WriteLine(this.name);
}
public static void ShowConut()
{
Console.WriteLine(conut);
}
}
}
}
类中的静态字段或方法只能在程序运行期间实例化一次,上例结果是3
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication9
{
class Program
{
static void Main(string[] args)
{
employee a = new employee();
employee b = new employee();
employee c = new employee();
employee.ShowConut();
}
class employee
{
public static int conut;
public employee()
: this("li", "1")
{
}
public employee(string n,string I)
{
Name = n;
ID1 = I;
conut += 1;
}
string name;
public string Name
{
get { return name; }
set { name = value; }
}
string ID;
public string ID1
{
get { return ID; }
set { ID = value; }
}
public void showname()
{
Console.WriteLine(this.name);
}
public static void ShowConut()
{
Console.WriteLine(conut);
}
}
}
}