覆盖代码 [英] override code
本文介绍了覆盖代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
public class N
{
public int M()
{
return 20;
}
public class O
{
public virtual int M1(int x, int y)
{
return 10;
}
}
}
public class P
{
//override the virtual method M present in class O
// public override int M1(int x, int y)
// {
// return 30;
// }
}
我的目标是覆盖O类中的虚拟方法M.我做了但是我收到了错误。任何人都可以告诉我任何其他方法吗?
my Aim is to override the virtual method M present in class O. I did but i am getting error. Can anybody tell me any other way to do it???
推荐答案
P类没有继承O类,所以你会得到一个不合适的错误可以找到方法来覆盖。此代码将编译:
Class P does no inherit from class O so you will get an error that no suitable method could be found to override. This code will compile:
public class N
{
public int M()
{
return 20;
}
public class O
{
public virtual int M1(int x, int y)
{
return 10;
}
}
}
public class P : N.O
{
//override the virtual method M present in class O
public override int M1(int x, int y)
{
return 30;
}
}
这篇关于覆盖代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文