C#面试题整理

.NET笔试题集(一):https://www.cnblogs.com/Jacob-Wu/p/5667502.html

C#常见面试题(附答案)

【学习笔记】C#面试题(一)

C# .NET面试题(100道面试题)

《C#程序设计》 习题集

------------------------------------------------------------------------------------------------------------

输出结果:

 public struct Point

    {

        public int x;

        public int y;

        public Point(int x, int y)

        {

            this.x = x;

            this.y = y;

        }

    }

            Point p1 = new Point(100, 100);

            Point p2 = p1;

            p1.x = 200;

            Console.WriteLine("{0},{1}", p1.x, p2.x);

答案:

200,100

解答:结构体是复制传递的。

 public Point

    {

        public int x;

        public int y;

        public Point(int x, int y)

        {

            this.x = x;

            this.y = y;

        }

    }

            Point p1 = new Point(100, 100);

            Point p2 = p1;

            p1.x = 200;

            Console.WriteLine("{0},{1}", p1.x, p2.x);

答案:

200,200

解答:Point类地址指向X内容都是200

------------------------------------------------------------------------------------------------------------

class Program
    {
        static void Main(string[] args)
        {
            MyClass y = new MyClass();
            BaseClass x = y;
            x.i = 100;
            Console.WriteLine("{0},{1}", x.i, y.i);//100,0   x.i = 100,已经给他赋值了100,所以x.i输出100.而y.i,y是myclass的一个对象,定义之后没做任何赋值的动作,而int的默认值...
            Console.ReadLine();

        }
}

    class BaseClass
    {
        public int i;
     }


    class MyClass:BaseClass
    {
        public new int i;
    }

------------------------------------------------------------------------------------------------------------

以下程序的输出结果是(b)。

enum Color

{ Red, Green = 2, Blue }

static void Main(string[] args)

{

Color c = 0;//所有能确定为0的常量表达式都能隐式的转换成Enum,所以Color c = 0;并不会报错。如果Color c = 1会报错

Color c1 = (Color )2;

Console.WriteLine("{0},{1}", c,c1 );

Console .Read ();

}

a) Green,Red b) Red,Green c) Red,Blue d) Green,Blue

------------------------------------------------------------------------------------------------------------

 

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值