Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1037321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:50:20+00:00 2026-05-16T14:50:20+00:00

I have a .Net library. say with 2 public functions. say one is Summmator

  • 0

I have a .Net library. say with 2 public functions. say one is Summmator which takes 2 arguments and does A+B. Another function simpleMultiplicator which takes 2 arguments: a number to multiplicate and count of times it should be multiplicated. A simpleMultiplicator function when called uses Summmator function. So it is my library. It is compiled into dll for .net4. In my programm I want to extend or modify Summator function so that when I call simpleMultiplicator it would use my modification of original Summator function. Is it possible in .net4, how to do it?

(C#, visual-C++)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T14:50:21+00:00Added an answer on May 16, 2026 at 2:50 pm

    It depends on how you design your classes. You state that your library exports two public functions, but they need to be defined on a class either as static or instance method, so you can make use of object-orientated principles like inheritance or polymorphism to achieve what you want.

    Here is an example using inheritance:

    namespace MyLibrary
    {
        public class MyMath
        {
            // Be aware of the virtual keyword which enables overriding the method
            public virtual int Summmator(int a, int b)
            {
                return a + b;
            }
    
            public int SimpleMultiplicator(int a, int b)
            {
                int result = 0;
                for (int i = 0; i < b; i++)
                {
                    result = Summmator(result, a);
                }
            }
        }
    }
    
    namespace MyProgram
    {
        using MyLibrary;
    
        public class MyExtendedMath : MyMath
        {
            public override int Summmator(int a, int b)
            {
                return a + 2 * b;
            }
        }
    
        public static class Program
        {
            public static void Main()
            {
                MyMath math = new MyExtendedMath();
                int result = math.SimpleMultiplicator(2, 3);
    
                Console.WriteLine(result);
            }
        }
    }
    

    Another way is to use polymorphism:

    namespace MyLibrary
    {
        public interface ISummmator
        {
            int Summmator(int a, int b);
        }
    
        public class Summmator : ISummator
        {
            public int Summmator(int a, int b)
            {
                return a + b;
            }
        }
    
        public static class MyMath
        {
            public static int SimpleMultiplicator(int a, int b, ISummmator summmator)
            {
                int result = 0;
                for (int i = 0; i < b; i++)
                {
                    result = summmator.Summmator(result, a);
                }
            }
        }
    }
    
    namespace MyProgram
    {
        using MyLibrary;
    
        public class MySummmator : ISummmator
        {
            public int Summmator(int a, int b)
            {
                return a + 2 * b;
            }
        }
    
        public static class Program
        {
            public static void Main()
            {
                int result = MyMath.SimpleMultiplicator(2, 3, new MySummmator());
    
                Console.WriteLine(result);
            }
        }
    }
    

    Best Regards,
    Oliver Hanappi

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class library project in .net say A which when built will
I have a question regarding the .NET Task Parallel Library's error handling. In which
If i have a library which is compiled in .NET 4 and reference it
I have an asynchronous library which is compiled under .NET 3.5, since it's used
i have situation in which i have some library projects, say DataProcessors,Lib2 , included
Let’s say I have a library, in which I added a few Console.WriteLine(..) statements
Let's say I have written a Class Library (dll) in .Net and now I
I have an ASP.NET application that uses a custom .NET library (a .DLL file).
I have an ASP.NET VB.NET web project that references a VB.NET class library. I
I have a class library (.NET) with a reference to a web service (in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.