C#面试题(曾经面试过三次)

xiaoxiao2021-02-27  782

1:求输出结果

 static void Main(string[] args)

        {             int x = 20;

            int y = 40;

   GetResult(ref x, y);  

   Console.WriteLine("X:{0},Y:{1}", x, y);

        }

  static void GetResult(ref int x, int y)         {             x = x + y;             y = x + y;         }

 结果:X:60Y:40

我自己用Lambda表达式写了一下

 static void Main(string[] args)

        {             int x = 20;

            int y = 40;

    Test_Void = (ref int X, int Y) => 

       {                     X = X + Y;                     Y = X + Y;                 };

   Console.WriteLine("X:{0},Y:{1}", x, y);

        }

 结果:X:60Y:40

个人见解:这个面试题主要考的是对ref参数的理解。

2:求输出的结果

class Program  {

    static void Main(string[] args)             {                 A aa = new B();                 aa.Fun();                 Console.Read();             }

}

   public abstract class A     {         public A()         {             Console.WriteLine("A");         }         public virtual void Fun()         {             Console.WriteLine("A.Fun.()");         }     }     public class B : A     {         public B()         {             Console.WriteLine("B");         }         public new void Fun()         {             Console.WriteLine("B.Fun.()");         }     }

结果:A   B    A,Fun();

个人见解:继承abstract抽象类的方法执行顺序

转载请注明原文地址: https://www.6miu.com/read-103.html

最新回复(0)