帮助'是'命令...... [英] Help with the 'is' command...

查看:70
本文介绍了帮助'是'命令......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我''是''命令如何与派生类相关?


例如 -

A类{}

B组:A {}

对象o = new B();


if(o是A ){...}


上述if语句应该返回true还是false?


Thanx。

Can someone tell me how the ''is'' command works in relation to derived classes?

For example -
Class A {}
Class B : A {}

object o = new B();

if (o is A) {...}

Should the above if statement return true or false?

Thanx.

推荐答案

2003年11月19日星期三08:01:04 -0800,好奇1

< an ******* @ discussions.microsoft.com>写道:
On Wed, 19 Nov 2003 08:01:04 -0800, "curious1"
<an*******@discussions.microsoft.com> wrote:
有人可以告诉我''是''命令如何与派生类相关?

例如 -
A类{}
B类:A {}

对象o = new B();

if(o是A){...}
上述if语句应该返回true还是false?

Thanx。
Can someone tell me how the ''is'' command works in relation to derived classes?

For example -
Class A {}
Class B : A {}

object o = new B();

if (o is A) {...}

Should the above if statement return true or false?

Thanx.




我的投票将是假的,它''不是A - 它是B.


简单到试试,如果你把一个

的小测试应用放在一起会得到什么结果?


-

Jeff Gaines Damerham Hampshire英国



My vote would be false, it''s not A - it''s B.

Simple enough to try though, what results do you get if you put a
small test app together?

--
Jeff Gaines Damerham Hampshire UK


对不起,


我自己的错是因为没有真正从原版中派生出来的(忘记了:B的定义中的A)。


再次。
Sorry all,

My own fault for not actually deriving the class from the original (forgot the :A in the definition of B).

Thanx again.


Jeff Gaines< je ** @ jgaines.co.uk>写道:
Jeff Gaines <je**@jgaines.co.uk> wrote:
2003年11月19日星期三08:01:04 -0800,curious1
< an ******* @ discuss.microsoft.com>写道:
On Wed, 19 Nov 2003 08:01:04 -0800, "curious1"
<an*******@discussions.microsoft.com> wrote:
有人可以告诉我''是''命令如何与派生类相关?

例如 -
A类{}
B类:A {}

对象o = new B();

if(o是A){...}
上述if语句应该返回true还是false?

Thanx。
Can someone tell me how the ''is'' command works in relation to derived classes?

For example -
Class A {}
Class B : A {}

object o = new B();

if (o is A) {...}

Should the above if statement return true or false?

Thanx.



我的投票将是假的,它不是A - 它是B。



My vote would be false, it''s not A - it''s B.




不,正确的答案是真的,因为它*是* A以同样的方式

字符串也是一个对象。


有关详细信息,请参阅ECMA C#规范的第14.9.9节。


-

Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet

如果回复小组,请不要给我发邮件



No, the correct answer is true, because it *is* an A in the same way
that a String is also an Object.

See section 14.9.9 of the ECMA C# spec for more details.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


这篇关于帮助'是'命令......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆