Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all
Actually i have one dll name demodll.
which contains this code:

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace demoDll
{
    public class Class1
    {
        public virtual int ADDNumbers(int a, int b,int c)
        {
            return 0;

        }
    }

}


now i am adding this dll into another dot net application as a reference.
i want to override this ADDNumbers function in my dot net application.
i want to write implementation for this function.
how can i do it??
Anyone have any sample code or any tutorial which i can go through..
please help..
god bless you all
thank you..:)
Posted
Comments
[no name] 29-Aug-12 7:36am    
What do you mean that you want to override this method? If you want to call a different method than this one then call the other method. There is no "overriding" here.
MAU787 29-Aug-12 7:54am    
i just want to know if there any way we can implement function which is declared in dll?

Yesterday, there was a correct answer. Now it's gone, so I'm going to reproduce it here:

Change your in-dll-code to
C#
public abstract class Class1
{
    public abstract int ADDNumbers(int a, int b,int c);
}

This doesn't provide any implementation for AddNumbers() at all, but is enforcing that you override it in every derived class.

Your actual application includes the dll. Do the subclassing there including the implementation of AddNumbers().

If that's all you want from Class1, you can also turn it into an interface instead of a class. That would allow the classes in your application to derive from something else and implement this interface at the same time.

Oh, and the derived class would be something like
C#
public class Class2 : Class1
{
    // The compiler will not allow any Class1-derived
    //   class unless it implements AddNumbers()
    public override int ADDNumbers(int a, int b, int c)
    {
        return( a + b + c);
    }
}
 
Share this answer
 
Reference that DLL in another project.

Use the namespace (using demoDll).

Extend the class (public class ImplementingClass : Class1) and override the method as normal
public class ImplementingClass : Class1 {
 public override int ADDNumbers(int a, int b, int c){ ... }
}


It looks like you're trying to do a 'pure virtual function' (C++ terminology) in which case you should make the method abstract, not virtual, in the DLL, and likely make Class1 an interface instead.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900