Tag: 隐式

有没有办法在C#中进行动态隐式类型转换?

给定此类具有隐式转换运算符: public class MyDateTime { public static implicit operator MyDateTime(System.Int64 encoded) { return new MyDateTime(encoded); } public MyDateTime(System.Int64 encoded) { _encoded = encoded; } System.Int64 _encoded; } 我现在可以做以下事情: long a = 5; MyDateTime b = a; 但不是以下内容: long f = 5; object g = f; MyDateTime h = g; 这给出了编译时间: 无法将类型’object’隐式转换为’MyDateTime’。 我感觉合理。 现在我修改前面的例子如下: long f […]