C # why can't we override a static property? (how high-level classes can invoke a base class method with high-level data)

My question is probably not well formulated, and it is probably a hoax, 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");
    }
}

Man - man Woman - man

Man, man, woman is in my database, but different requests are needed.

I do not want to duplicate these requests, so I thought it would be nice to store them in a static property in each class.

I got some low-level stuff (not figured there) that lies in the base class (coz, which I don't want to duplicate), and I wanted the inherited classes to call the base class method with the context of the allocated classes

. [inherited] somemethod() person.somemethod(), ,

+5
2

, , :

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;
}
+3

? .net , , .

, ...

, sql , Person, Man Woman .., Person GetSql , .

, , .

+3

All Articles