CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2006
    Posts
    99

    interface as a parameter

    anyone can point me as to how to one can pass an interface as a parameter? how i go about implementing the code below?

    <code>
    public class A
    {
    public void dome(IDo intface)
    {
    intface.callme();
    }

    public void Method()
    {
    MessageBox.Show("A");
    }
    }



    public interface IDo
    {
    void callme();
    }

    class main
    {
    A instA = new A();
    a.dome(//do i send it theimplementation? if not where is the implemenation implemented?
    }
    </code>

  2. #2
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    Re: interface as a parameter

    Very simple:
    Code:
    class Foo : IDo
    {
      public void callme() {}
    }
    
    Foo f = new Foo();
    A instA = new A();
    a.dome(f);
    • Make it run.
    • Make it right.
    • Make it fast.

    Don't hesitate to rate my post.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured