C#面試題來自上海奮泰國際貿易有限公司,20131121

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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章