C#面试题来自上海奋泰国际贸易有限公司,20131121

来源:互联网 发布:ubuntu设置动态ip地址 编辑:程序博客网 时间:2024/04/30 08:26

1.数据类型转换

float f = -123.56f;

            int i = (int)f;

            Response.Write(i);

输出:-123

 2.父类子类成员变量初始化顺序

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace ShanghaiTest

{

    public class A

    {

        public static int x;

        static A()

        {

            x = B.Y + 1;

        }

    }

    class B

    {

        public static int Y = A.x + 1;

        static B() { }

 

    }

}

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace ShanghaiTest

{

    class Program

    {

        static void Main(string[] args)

        {

            Console.WriteLine("x={0};y={1}",A.x, B.Y);

        }

    }

}

x=2;y=1

请按任意键继续. . .

 

 3.值类型地址比较

         int i = 10;

            int j = 10;

            bool same= object.ReferenceEquals(i, j);

            Console.WriteLine(same);

输出:False