码迷,mamicode.com
首页 > Windows程序 > 详细

C# 类是否相等

时间:2015-01-21 10:16:35      阅读:214      评论:0      收藏:0      [点我收藏+]

标签:c#

public class ShopItem {
    public string name;
    public int count;
    public int buyPrice;
    public int sellPrice;
    public float price;

    public ShopItem()
    {
    }

    public ShopItem(string _name, int _count, int _buyPrice, int _sellPrice, float _price)
    {
        // TODO: Complete member initialization
        this.name = _name;
        this.count = _count;
        this.buyPrice = _buyPrice;
        this.sellPrice = _sellPrice;
        this.price = _price;
    }

    public override bool Equals(object obj)
    {
        if (obj.GetType().Equals(this.GetType()) == false)
        {
            return false;
        }

        ShopItem tempObj = (ShopItem)obj;

        return (name.Equals(tempObj.name))      &&
            (count == tempObj.count)            && 
            (buyPrice == tempObj.buyPrice)      && 
            (sellPrice == tempObj.sellPrice)    && 
            (Mathf.Abs(price - tempObj.price) < 0.0001);
    }
}

C# 类是否相等

标签:c#

原文地址:http://blog.csdn.net/lihuozhiling0101/article/details/42963999

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!