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 7690525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:25:03+00:00 2026-05-31T20:25:03+00:00

My question is probably not well phrased and it’s probably a dupe but here

  • 0

My question is probably not well phrased and it’s probably a dupe but here I go

class person {
    protected static string request = "select * from person where gender in ('male','female')";
    public string sharedmethod()
    {
        return "the request is" + request;
    }
}

class man:person
{
    override protected static string request = "select person.*,man.* from person,men where mytype in ('male') ";
    DateTime dateOfFirstCar;
}

class woman:person
{
    override protected static string request = "select person.*,woman.* from person,women where mytype in ('female') ";
    DateTime dateOfFirstITBAG;
}

class Program
{
    static void Main(string[] args)
    {
        if (new person().sharedmethod() == new man().sharedmethod())
            Console.Write("too bad query is the same in base and dervide class");
    }
}

A man is a person
A woman is a person
Person,man,woman exist in my database but need different queries

I don’t want to duplicate those queries so I thought it was a good idea to store them in a static property in each class.

I got some low level stuff (not figured there) that lie in the base class (coz I don’t want to duplicate) and I wanted inherited classes to call base class method with the context of the herited classes

I want man.[inherited]somemethod() to execute person.somemethod() but with variables coming from man

thank you

  • 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-31T20:25:04+00:00Added an answer on May 31, 2026 at 8:25 pm

    Add a non-static property covering the static string, and reference that property instead:

    class person {
        private const string request = "select * from person where gender in ('male','female')";
        protected virtual string Request {get {return request;}}
        public string sharedmethod() {
            return "the request is" + Request;
        }
    }
    
    class man:person {
        private const string request = "select person.*,man.* from person,men where mytype in ('male') ";
        protected override string Request {get {return request;}}
        DateTime dateOfFirstCar;
    }
    
    class woman:person {
        private const string request = "select person.*,woman.* from person,women where mytype in ('female') ";
        protected override string Request {get {return request;}}
        DateTime dateOfFirstITBAG;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

TLDR; this is not a well-phrased question, so you should probably not bother with
Well this is not the first time im asking these question here but I
The question is probably not the best one to describe my issue but I
I should probably not ask a generic question with a specific example, but I
I realize this question has probably been asked numerous times, but I have not
I've already posted this question here , but since it's maybe not that Qt-specific,
I have this question on the Wordpress stack exchange as well, but not having
Well this is probably a stupid question with a simple answer but when using
I have a general question that was probably answered somewhere here, but using search
There is probably a simple answer to this question but I do not have

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.