现在的位置: 首页 > 综合 > 正文

。net中一些常用的类方法

2013年10月11日 ⁄ 综合 ⁄ 共 364字 ⁄ 字号 评论关闭


随机数生成

 Random random = new Random();
            random.Next(0,99);//生成一个>=0,<99的随机数

属性访问器:

public string Name
{
get {return this.name;}
set {this.name=value;}
}

上面的代码也可以简写为:

public string Name

{

get;

set;

}

重写Equal函数:

public override bool Equals(object obj)
        {

            MyFirstClass tt = (MyFirstClass)obj;
            if (this == tt)
                return true;
            else if(this.x==tt.x&&this.y==tt.y)
                return true
            else
                return false;
            
          //  return base.Equals(obj);
        }

抱歉!评论已关闭.