.NET面试题整理(持续更新)

 1、已知值类型保存在线程栈中,引用类型保存在堆中

struct Point{
    public int x,y;
}
public sealed class program{
    public static void Mian()
    {
        ArrayList a =new ArrayList();
        Point p;
        for (int i = 0; i < 10; i++)
        {
            p.x=p.y=i;
            a.Add(p);
        }
    }
}

那么问题来了,ArrayList存的是值类型的Point结构,还是point结构的地址,为什么?

2、以下代码是否有问题,有问题的话是编译有问题还是运行有问题

public static Void Main()
{
    Int32 x=5;
    Object o=x;
    Int16 y=(Int16)o;
}

3、两个Point中的字段x,y会被初始化成多少,0还是5

    internal struct Point
    {
        public int x, y;
        public Point()
        {
            x = y = 5;
        }
    }
    internal class Rectangle
    {
        public Point left, right;
        public Rectangle()
        {

        }
    }

4、以下代码将进行几次装箱操作,都是那些地方需要进行装箱

public static void Mian()
{
    Int v=5;
    Object o=v;
    System.Console.WriteLine(v+","+(int)o);
}
原文地址:https://www.cnblogs.com/bjjjunjie/p/12228769.html