How can i implicitly convert my class to another type?

后端 未结 3 621
自闭症患者
自闭症患者 2021-01-19 05:42

For example implicitly

MyClass myClass = new MyClass();
int i = myClass;
3条回答
  •  不知归路
    2021-01-19 05:57

    class MyClass 
    {
       public static implicit operator int(MyClass myClass) 
       {
          // code to convert from MyClass to int
       }
    }
    

    Take a look there : implicit

提交回复
热议问题