C# code to handle different classes with same method names

前端 未结 9 1556
夕颜
夕颜 2020-12-10 01:56

Let\'s say you have two different C# classes A and B that while not deriving from the same base class do share some of the same names for methods.

9条回答
  •  再見小時候
    2020-12-10 02:42

    Either you will have to use an Interface (or Base class) as shown by Zach and astander, or you will have to case the object before using:

    public void make_connection(Object x) 
    { 
      ((A)x).connect() ; 
      // Do some more stuff... 
      x.disconnect() ; 
      return ; 
    } 
    

提交回复
热议问题