CODE:
using System;
namespace CsStudy
{
class Per
{
public int p = 5;
public static implicit operator int(Per a)//自定义隐式类型转换
{
return a.p + 1;
}
public static explicit operator Per(int a)//自定义显式类型转换
{
return new Per();
}
}
class Program
{
static void Main()
{
int a = 1;
Per pr = new Per();
pr = (Per)a;
a = pr;
Console.ReadKey();
}
}
}