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