在CLR中使用“as”关键字对VS进行强制转换
public interface IMyInterface{ void AMethod();}public class MyClass : IMyInterface{ public void AMethod() { //Do work } // Other helper methods....}public class Implementation{ IMyInterface _MyObj; MyClass _myCls1; MyClass _myCls2; public Implementation() { _MyObj = new MyClass(); // What is the difference here: _myCls1 = (MyClass)_MyObj; _myCls2 = (_MyObj as MyClass); }}
宝慕林4294392
慕妹3146593