C#中潜在的面试问题......太辛苦? [英] C# Potential Interview Question…Too hard?

查看:159
本文介绍了C#中潜在的面试问题......太辛苦?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果没有运行该code,确定哪些方法将被调用:

Without running this code, identify which Foo method will be called:

class A
{
   public void Foo( int n )
   {
      Console.WriteLine( "A::Foo" );
   }
}

class B : A
{
   /* note that A::Foo and B::Foo are not related at all */
   public void Foo( double n )
   {
      Console.WriteLine( "B::Foo" );
   }
}

static void Main( string[] args )
{
   B b = new B();
   /* which Foo is chosen? */
   b.Foo( 5 );
}

哪些方法?为什么?没有作弊通过运行code。

Which method? And why? No cheating by running the code.

我发现这个难题在网络上;我喜欢它,我想我会用它作为一个面试问题...意见?

I found this puzzle on the web; I like it and I think I'm going to use it as an interview question...Opinions?

编辑:我不会让这种错误判断一个候选人,我会用它的方式来打开对C#和CLR本身就是一个更充分的讨论,这样我就可以拿到的考生能力有很好的理解

I wouldn't judge a candidate on getting this wrong, I'd use it as a way to open a fuller discussion about the C# and CLR itself, so I can get a good understanding of the candidates abilities.

来源: <一个href="http://netpl.blogspot.com/2008/06/c-puzzle-no8-beginner.html">http://netpl.blogspot.com/2008/06/c-puzzle-no8-beginner.html

推荐答案

我真的不会用这个作为一个面试问题。我知道答案,这背后的原因,但这样的事情应该拿出所以很少,这不应该是一个问题。知道答案确实没有表现出很大的关于候选人的能力,code。

I really wouldn't use this as an interview question. I know the answer and the reasoning behind it, but something like this should come up so rarely that it shouldn't be a problem. Knowing the answer really doesn't show much about a candidate's ability to code.

请注意,你会得到相同的行为,即使A.Foo是虚拟和B覆盖它。

Note that you'll get the same behaviour even if A.Foo is virtual and B overrides it.

如果你喜欢C#的困惑和古怪,我有几个过(包括本)

If you like C# puzzles and oddities, I've got a few too (including this one).

这篇关于C#中潜在的面试问题......太辛苦?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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