要扩展或修改继承的方法、属性、索引器或事件的抽象实现或虚实现,必须使用 override 修饰符
比如:
class TestOverride
{
public class Employee
{
public string name
// Basepay is defined as protected, so that it may be
// accessed only by this class and derrived classes.
protected decimal basepay
// Constructor to set the name and basepay values.
public Employee(string name, decimal basepay)
{
this.name = name
this.basepay = basepay
}
// Declared virtual so it can be overridden.
public virtual decimal CalculatePay()
{
return basepay
}
}
// Derive a new class from Employee.
public class SalesEmployee : Employee
{
// New field that will affect the base pay.
private decimal salesbonus
// The constructor calls the base-class version, and
// initializes the salesbonus field.
public SalesEmployee(string name, decimal basepay,
decimal salesbonus) : base(name, basepay)
{
this.salesbonus = salesbonus
}
// Override the CalculatePay method
// to take bonus into account.
public override decimal CalculatePay()
{
return basepay + salesbonus
}
}
}
详情参阅:http://msdn.microsoft.com/zh-cn/library/ebca9ah3%28VS.80%29.aspx
不知道你是怎么反编译的,我得到的结果和你是完全不一样的。
首先ValidateUser是静态方法,又何来虚方法一说呢?其次反编译的到的代码如下:
public static bool ValidateUser(string username,string password){
return Provider.ValidateUser(username,password)
}
Provider是Membership中的一个静态属性。类型为MembershipProvider,该类型为抽象类,定义了Membership中的所有数据操作方法,针对不同的数据库类型需要实现相应的MembershipProvider,通过config文件将具体实现类注入到Membership类中。
.net中有针对SqlServer的SqlMembershipProvider默认实现。完全是.net实现,与C一点关系都没有。
欢迎分享,转载请注明来源:夏雨云
评论列表(0条)