Overloading an "External" Class?

This is a discussion on Overloading an "External" Class? within the C# Programming forums, part of the General Programming Boards category; Ok, my inheritance knowledge and fields in that area are not that great. How can i overload a method of ...

  1. #1
    #junkie
    Join Date
    Oct 2004
    Posts
    240

    Overloading an "External" Class?

    Ok, my inheritance knowledge and fields in that area are not that great.


    How can i overload a method of a class i have no control over?

    For example, look at the following method:
    Code:
    object.Equals( object objectA, object objectB )
    How could i add an overload to that, so anywhere i use that i can also use
    Code:
    object.Equals( object objectA, object objectB, 
             object objectC, object objectD )

    I do not want to modify the Equals function, this is just an example. Equals represents a method i did not make, and it exists somewhere else, but i want to simply add a couple overloads so i dont have to create my own Class & Method just to do what i could squeeze into that.
    01110111011000010110110001100100011011110010000001 11000101110101011010010111010000100000011011000110 10010110011001100101001000000111100101101111011101 0100100000011011100111010101100010

  2. #2
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    You can't (though, you'll be able to do that in C# 3.0 with extension methods). Your only real option is to make a class that inherits from object and adds your Equals method.
    Code:
    class SmartObject: object
    {
       public void Equals( object objectA, object objectB, 
             object objectC, object objectD )
       {
          
       }
    }

  3. #3
    #junkie
    Join Date
    Oct 2004
    Posts
    240
    bummer. Oh well, thanks for the quick reply
    01110111011000010110110001100100011011110010000001 11000101110101011010010111010000100000011011000110 10010110011001100101001000000111100101101111011101 0100100000011011100111010101100010

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Inherite nonvirtual class functionality
    By DrSnuggles in forum C++ Programming
    Replies: 2
    Last Post: 04-30-2009, 01:52 PM
  3. My Window Class
    By Epo in forum Game Programming
    Replies: 2
    Last Post: 07-10-2005, 02:33 PM
  4. overloading the division operator with Integer Class
    By silk.odyssey in forum C++ Programming
    Replies: 3
    Last Post: 05-17-2004, 06:59 PM
  5. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 06:18 AM

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