interface implementation

This is a discussion on interface implementation within the C# Programming forums, part of the General Programming Boards category; Hello everyone, I am migrating from C++ to C#. The following compile error makes me confused. Suppose in interface there ...

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    1,579

    interface implementation

    Hello everyone,


    I am migrating from C++ to C#. The following compile error makes me confused. Suppose in interface there is a method called Abc which returns object, and in the implementation class, there is also a method called Abc, but the return type is List<int>, I think List<int> is already a type (derived type) of object, so no need to explicitly implement Interface.Abc again, but here is a compile error.

    Code:
    D:\Visual Studio 2008\Projects\ConsoleApplication1\ConsoleApplication1\Program.cs(14,11): error CS0738: 'MyList.Foo' does not implement interface member 'MyList.IFoo.Abc()'. 'MyList.Foo.Abc()' cannot implement 'MyList.IFoo.Abc()' because it does not have the matching return type of 'object'.
    Could anyone show me what is the rule I break here please?

    Code:
    public class MyList
    {
    
        interface IFoo
        {
            object Abc();
        }
    
        class Foo : IFoo
        {
            public Foo()
            {
    
            }
            
            public List<int> Abc()
            {
                return new List<int>;
            }
    
        }
    
        static void Main()
        {
            Foo f = new Foo();
            return;
        }
    }

    thanks in advance,
    George

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,470
    compiler thinks that List<int> and object are different types... You know, I think I agree with it.
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Thanks vart,


    Question answered.

    Quote Originally Posted by vart View Post
    compiler thinks that List<int> and object are different types... You know, I think I agree with it.

    regards,
    George

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to get RSSI value, send to sensor, sensor receive package, repackage it?
    By techissue2008 in forum Networking/Device Communication
    Replies: 1
    Last Post: 03-04-2009, 09:13 AM
  2. interface, implementation, & application files
    By trongsi in forum C++ Programming
    Replies: 4
    Last Post: 04-08-2006, 02:11 PM
  3. OOP in C
    By lyx in forum C Programming
    Replies: 4
    Last Post: 11-23-2003, 12:12 PM
  4. Replies: 2
    Last Post: 02-11-2002, 12:03 PM
  5. Exporting Object Hierarchies from a DLL
    By andy668 in forum C++ Programming
    Replies: 0
    Last Post: 10-20-2001, 01:26 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21