覆盖与新 [英] Overriding vs. New
问题描述
我没理解。覆盖基础
类的方法与隐藏它们之间的主要区别是什么?
谢谢,
/ m
I don''t get it. What''s the main differences between overriding a base
class''s methods vs. hiding them?
Thanks,
/m
推荐答案
Hi Muscha
覆盖=你使用基类的所有属性你只是
会覆盖mainimplementation。
当你覆盖一个函数结构时(public override void(int,int))
必须是相同的。
新的你可以使用相同的方法名作为基类中的方法但是
结构可以不同
并且你使用''正常''类中的变量,
希望这有助于
" muscha" <亩**** @ no.spam.net>在消息中写道
news:eZ ************** @ TK2MSFTNGP11.phx.gbl ...
Hi Muscha
overriding = you use all the properties from the base class you just
overrides the mainimplementation.
when you override a function the structure (public override void (int,int))
must be the same.
with new you can use the same method name as a method in the baseclass but
the structure can be different
and you use the properites, variables from the ''normal'' class
hope this helps
"muscha" <mu****@no.spam.net> wrote in message
news:eZ**************@TK2MSFTNGP11.phx.gbl...
我不是得到它。重写基础类的方法与隐藏它们之间的主要区别是什么?
谢谢,
/ m
I don''t get it. What''s the main differences between overriding a base
class''s methods vs. hiding them?
Thanks,
/m
" Stefan" < SH **** @ steffsworld.ch>在留言中写道
新闻:%2 **************** @ tk2msftngp13.phx.gbl ...
"Stefan" <sh****@steffsworld.ch> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hi Muscha
overriding =你使用基类的所有属性,你只需要覆盖mainimplementation。
当你覆盖一个函数时,结构(public override void
(int) ,int))必须是相同的。
使用新的你可以使用相同的方法名称作为基类中的方法,但结构可以是不同的
你使用的属性,变量来自''正常''类
Hi Muscha
overriding = you use all the properties from the base class you just
overrides the mainimplementation.
when you override a function the structure (public override void (int,int)) must be the same.
with new you can use the same method name as a method in the baseclass but
the structure can be different
and you use the properites, variables from the ''normal'' class
所以使用new基类的所有方法名称都变得无法使用?
比如说:
class Base
{
public void calculatePay(int a,int b){};
public void calculatePay(int a,int b,int c){};
}
类派生:基础
{
new public void calculatePay(int a){} //将在Base中隐藏所有calculatePay
方法?
}
还有new关键字难道你不能使用
基类的所有属性,如果它们是公开的吗?
谢谢,
/ m
So with "new" all the method name of the base class rendered unusable?
Say for example:
class Base
{
public void calculatePay(int a, int b) {};
public void calculatePay(int a, int b, int c) {};
}
class Derived : Base
{
new public void calculatePay(int a) {} // will make all calculatePay
methods in Base hidden?
}
Also with "new" keyword shouldn''t you be able to use all the properties from
the base class as well if they are publicly available?
Thanks,
/m
使用''new''关键字,你说你的方法使用相同的名称,但
与你的基本方法完全不同的东西。
确保你有权访问基类的属性和变量(制作一个
思考错误:-))。
" muscha" <亩**** @ no.spam.net>在消息中写道
news:Og ************** @ TK2MSFTNGP09.phx.gbl ...
with the ''new'' keyword you say that your method uses the same name but does
something completely different to your base method.
sure you have access to properties and variables to the base class (made a
thinking mistake :-) ).
"muscha" <mu****@no.spam.net> wrote in message
news:Og**************@TK2MSFTNGP09.phx.gbl...
" Stefan" < SH **** @ steffsworld.ch>在消息中写道
新闻:%2 **************** @ tk2msftngp13.phx.gbl ...
"Stefan" <sh****@steffsworld.ch> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hi Muscha
overriding =你使用基类的所有属性,你只需要覆盖mainimplementation。
当你重写一个函数时,结构(public override void(int,int))
Hi Muscha
overriding = you use all the properties from the base class you just
overrides the mainimplementation.
when you override a function the structure (public override void (int,int))
必须是相同的。
使用new你可以使用相同的方法名作为基类
中的方法,但结构可以是不同的
并且你使用的属性,变量来自''正常''类
must be the same.
with new you can use the same method name as a method in the baseclass but the structure can be different
and you use the properites, variables from the ''normal'' class
所以使用new基类的所有方法名称都变得无法使用?
例如:
class Base
{
public void calculatePay( int a,int b){};
public void calculatePay(int a,int b,int c){};
}
类派生:基础
{
新的public void calculatePay(int a){} //会隐藏Base中的所有calculatePay
方法吗?
还有new关键字难道你不能使用基类的所有属性
So with "new" all the method name of the base class rendered unusable?
Say for example:
class Base
{
public void calculatePay(int a, int b) {};
public void calculatePay(int a, int b, int c) {};
}
class Derived : Base
{
new public void calculatePay(int a) {} // will make all calculatePay
methods in Base hidden?
}
Also with "new" keyword shouldn''t you be able to use all the properties
,如果它们是公开的吗?
谢谢,
/ m
from the base class as well if they are publicly available?
Thanks,
/m
这篇关于覆盖与新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!