且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

可以将一个变量转换为存储在另一个变量类型?

更新时间:2023-01-07 16:24:05

没有,你不能。 C#不执行鸭打字

No, you cannot. C# does not implement duck typing.

您必须实现接口和投给它。

You must implement an interface and cast to it.

(但也有尝试这样做。看的Duck打字项目一个例子。)

(However there are attempts to do it. Look at Duck Typing Project for an example.)