父类字段覆盖

编程有钱人了 编程有钱人了 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

public abstract class BaseEntity
{

public virtual int Id { get; set; }

public override bool Equals(object obj)
{
return Equals(obj as BaseEntity);
}

public virtual bool Equals(BaseEntity other)
{
if (other == null || !(other is BaseEntity))
{
return false;
}
return (this == (BaseEntity)other);
}

public override int GetHashCode()
{
return Id.GetHashCode();
}

public static bool operator ==(BaseEntity x, BaseEntity y)
{
if ((object)x == null && (object)y == null)
{
return true;
}

if ((object)x == null || (object)y == null)
{
return false;
}

return x.Id == y.Id;
}

public static bool operator !=(BaseEntity x, BaseEntity y)
{
return !(x == y);
}
}



public class Child:BaseEntity
{
public Int32 F_Id { get; set; }
public String Name{ get; set; }
}

我想用F_id覆盖掉父类的Id
这个要怎么玩?


PS:我是菜鸟
...全文

相关推荐

评论 9
收藏 已收藏
分享
返回顶部
编程有钱人了
C# 111,129 成员 642,540 内容