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