继承和静态 [英] inheritance and static
本文介绍了继承和静态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
考虑以下示例:
A级
{
公共静态方法()
{
/ * ... * /
}
}
B级: A
{
}
如果它被调用为B.Method()或者如何调用Method() A.Method()?
-
Semper Fidelis
Adam Klobukowski
*** @ gabo.pl
Consider following example:
class A
{
public static Method()
{
/* ... */
}
}
class B : A
{
}
How can i chcek in Method() if it was called as B.Method() or A.Method()?
--
Semper Fidelis
Adam Klobukowski
at***@gabo.pl
推荐答案
也许喜欢这个:
class testA
{
public void Method()
{System.Windows .Forms.MessageBox.Show(this.ToStrin g());}
}
class testB:testA
{
}
testA local_A = new testA();
local_A.Method();
testB local_B = new testB();
local_B.Method();
Frank Uray
" Adam Klobukowski"写道:
Maybe like this:
class testA
{
public void Method()
{System.Windows.Forms.MessageBox.Show(this.ToStrin g());}
}
class testB : testA
{
}
testA local_A = new testA();
local_A.Method();
testB local_B = new testB();
local_B.Method();
Frank Uray
"Adam Klobukowski" wrote:
请考虑以下示例:
A类
{
公共静态方法()
{
/ * ...... * /
}
}
B组:A
{
}
怎么能如果它被调用为B.Method()或A.Method(),我会在Method()中进行调整吗?
Semper Fidelis
Adam Klobukowski
at***@gabo.pl
嗨亚当,
查看生成的IL(使用Reflector解散
http://www.aisto.com/roeder/dotnet/ )看起来像A.Method的实际电话是
而不管你怎么写c#。
adam
Adam Klobukowski写道:
Hi Adam,
Looking at the generated IL (dissasembled using Reflector
http://www.aisto.com/roeder/dotnet/) it looks like the actual call is
to A.Method regardless of how you write the c#.
adam
Adam Klobukowski wrote:
考虑下面的例子:
A级
公共静态方法()
{
/ * ... * /
}
如果它被称为B.Method,我怎么能在Method()中使用它? )或A.Method()?
Semper Fidelis
Adam Klobukowski
在*** @ gabo.pl
" Adam Klobukowski <在*** @ gabo.pl>在消息中写道
news:e0 ********** @ nemesis.news.tpi.pl ...
"Adam Klobukowski" <at***@gabo.pl> wrote in message
news:e0**********@nemesis.news.tpi.pl...
请考虑以下示例:
A级
公共静态方法()
{
/ * ... * /
}
} > B类:A
如果它被调用为B.Method()或A.Method,我怎么能在Method()中使用它? )?
Consider following example:
class A
{
public static Method()
{
/* ... */
}
}
class B : A
{
}
How can i chcek in Method() if it was called as B.Method() or A.Method()?
A级{
public static void M(){M(false); }
protected static void M(bool derived){/ * biz * /}}
class B:A {new static void M(){AM(true);}}
class A {
public static void M() { M(false); }
protected static void M(bool derived){/* the biz */}}
class B : A{new static void M(){A.M(true);}}
这篇关于继承和静态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文