类的测试
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class myclass
{
private int intStudentId;//定义字段(私有成员)
public int _intStudentId //定义属性
{
get { return intStudentId; }
set
{
if (value< 0)
{
intStudentId = -value;
}
else intStudentId = value;
}
}
public myclass(string strName)//带参数的构造函数
{
Console.Write(strName);
}
public myclass()//默认构造函数
{
Console.Write("Hello!");
}
public static string GetNation (string strNation)//公有的静态方法(通过类可以访问,不同实例化)
{
return strNation;
}
}
class TestClass
{
static void Main(string[] args)
{
Console.Write("My Nation is:" + myclass.GetNation("China"));
Console.Write("\n");
myclass annclass = new myclass();
Console.Write("\n");
myclass lzlClass = new myclass("lzl");
Console.Write("\n");
lzlClass._intStudentId = -100;
Console.Write(lzlClass._intStudentId);
Console.ReadLine();
}
}
}