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

  • Home
  • SEARCH
  • 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 832607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:23:19+00:00 2026-05-15T04:23:19+00:00

is it possibly in c# to have some sort of base class functionality which

  • 0

is it possibly in c# to have some sort of base class functionality which is manipulated slightly based on the class. For instance say i have the following code (which will quite obviously not compile it’s meant to only be for demonstrative purposes)

class BaseFunctionality
{
    public virtual bool adminCall
    public static string MethodName(int id, string parameter)
    { 
        if (adminCall)
            return dbcall.Execute();
        else
            return dbcall.ExecuteMe();
    }
}
class Admin : BaseFunctionality
{
    override bool adminCall = true;
}
class Front : BaseFunctionality
{
    override bool adminCall = false;
}

Now what i would like to be able to do is;

string AdminCall = Admin.MethodName(1, "foo");
string FrontCall = Front.MethodName(2, "bar");

Is their any way to do something like this? I’m trying to do everything with static methods so i do not have to instantiate classes all the time, and have nice clean code which is only being manipulated in one place.

The idea behind this is so that there is minimal code repeating and makes things easier to expand on, so for instance another class could implement the BaseFunctionality later on.

  • 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-15T04:23:20+00:00Added an answer on May 15, 2026 at 4:23 am

    Your desire to use static methods is getting in the way of using inheritance properly. The base class in your example knows how to implement the functionality of the two sub-classes. A cleaner way of coding this would be:

        abstract class BaseFunctionality
        {
            public abstract string MethodName(int id, string parameter);
        }
    
        class Admin : BaseFunctionality
        {
            public override string MethodName(int id, string parameter)
            {
                return "dbcall.Execute()";
            }                        
        }
    
        class Front : BaseFunctionality
        {
            public override string MethodName(int id, string parameter)
            {
                return "dbcall.ExecuteMe()";
            }
        }
    

    you can then create other static methods or use singletons to access these methods if you must have static access. e.g.:

    string AdminCall = Admin.Instance.MethodName(1, "foo");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 447k
  • Answers 447k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer First of all, your DBMS (MySQL) does not need to… May 15, 2026 at 7:33 pm
  • Editorial Team
    Editorial Team added an answer It might be incidental, but changing the value of _SECURE_SCL… May 15, 2026 at 7:33 pm
  • Editorial Team
    Editorial Team added an answer Why not do it like this: for (var i=0; i<10;… May 15, 2026 at 7:33 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.