Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How can i know from which interface the method is calling?

How can i know from which interface the method is calling?

Scheduled Pinned Locked Moved C#
question
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Satish Developer
    wrote on last edited by
    #1

    namespace MYConsoleApplication
    {
    class Program
    {
    static void Main(string[] args)
    {

            int x = 3;
            int y = 2;
    
            x= (x==y++)?x+y:x-y;
    
            A ObjA = new A();
            ObjA.M1();
        }
    }
    
    interface Inf1
    {
         void M1();
         void M2();
    }
    
    interface Inf2
    {
         void M1();
    }
    
    class A: Inf1,Inf2
    {
        public void M1()
        {
            Console.Write("test");
        }
    
        public void M2()
        {
            Console.Write("test2");
        }
    }
    

    }

    From the above code ..how can i know from which interface the method M1() is overriding in Class A. Please let me know..if this is the case where tow interfaces contains same method..

    G. Satish

    N A 2 Replies Last reply
    0
    • S Satish Developer

      namespace MYConsoleApplication
      {
      class Program
      {
      static void Main(string[] args)
      {

              int x = 3;
              int y = 2;
      
              x= (x==y++)?x+y:x-y;
      
              A ObjA = new A();
              ObjA.M1();
          }
      }
      
      interface Inf1
      {
           void M1();
           void M2();
      }
      
      interface Inf2
      {
           void M1();
      }
      
      class A: Inf1,Inf2
      {
          public void M1()
          {
              Console.Write("test");
          }
      
          public void M2()
          {
              Console.Write("test2");
          }
      }
      

      }

      From the above code ..how can i know from which interface the method M1() is overriding in Class A. Please let me know..if this is the case where tow interfaces contains same method..

      G. Satish

      N Offline
      N Offline
      Nuri Ismail
      wrote on last edited by
      #2

      See "Avoiding Name Ambiguity" section of this[^] article. :)

      1 Reply Last reply
      0
      • S Satish Developer

        namespace MYConsoleApplication
        {
        class Program
        {
        static void Main(string[] args)
        {

                int x = 3;
                int y = 2;
        
                x= (x==y++)?x+y:x-y;
        
                A ObjA = new A();
                ObjA.M1();
            }
        }
        
        interface Inf1
        {
             void M1();
             void M2();
        }
        
        interface Inf2
        {
             void M1();
        }
        
        class A: Inf1,Inf2
        {
            public void M1()
            {
                Console.Write("test");
            }
        
            public void M2()
            {
                Console.Write("test2");
            }
        }
        

        }

        From the above code ..how can i know from which interface the method M1() is overriding in Class A. Please let me know..if this is the case where tow interfaces contains same method..

        G. Satish

        A Offline
        A Offline
        AspDotNetDev
        wrote on last edited by
        #3

        It is not overriding M1, it is implementing it for BOTH interfaces. If you wanted, you could also explicitly implement it for each interface (so that casting it as Inf1 and calling M1 will do something different than casting it as Inf2 and calling M1).

        [Forum Guidelines]

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups