Click here to Skip to main content
11,409,516 members (41,690 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# .NET DLL
hi all
Actually i have one dll name demodll.
which contains this code:

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..Smile | :)
Posted 29-Aug-12 2:33am
MAU7871.6K
Comments
Wes Aday at 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 at 29-Aug-12 7:54am
   
i just want to know if there any way we can implement function which is declared in dll?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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

Change your in-dll-code to
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
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);
    }
}
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 300
1 OriginalGriff 285
2 Dave Kreskowiak 115
3 Andy Lanng 115
4 Maciej Los 100
0 Sergey Alexandrovich Kryukov 8,731
1 OriginalGriff 6,895
2 Maciej Los 3,332
3 Abhinav S 3,248
4 Peter Leow 3,059


Advertise | Privacy | Mobile
Web03 | 2.8.150414.5 | Last Updated 30 Aug 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100