c#自定义类型的转换方式operator,以及implicit(隐式)和explicit (显示)声明

https://docs.microsoft.com/zh-cn/dotnet/csharp/language-reference/keywords/explicit

https://docs.microsoft.com/zh-cn/dotnet/csharp/language-reference/keywords/implicit

https://docs.microsoft.com/zh-cn/dotnet/csharp/language-reference/keywords/operator

Vector2隐匿转换例子

public struct Vector2 {
    public static implicit operator Vector2(Vector3 v){
        return new Vector2(v.x,v.y);
    }

    public static implicit operator Vector3(Vector2 v){
        return new Vector3(v.x,v.y,0);
    }
}
原文地址:https://www.cnblogs.com/kingBook/p/7026006.html