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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T13:19:50+00:00 2026-05-11T13:19:50+00:00

Should the following code give a warning? class Foo { public void Do() {

  • 0

Should the following code give a warning?

class Foo { public void Do() { /*...*/ } /*...*/ } class Bar : Foo { public static void Do()  { /*...*/ } /*...*/ } 

It gives:

‘Warning CS0108: ‘Bar.Do()’ hides inherited member ‘Foo.Do()’. Use the new keyword if hiding was intended.’

If I make a change to the code:

class Foo { public static void Do() { /*...*/ } /*...*/ } class Bar : Foo { public void Do()  { /*...*/ } /*...*/ } 

I get the same warning.

If I make the following change, however, the warning goes away.

class Foo { public void Do() { /*...*/ } /*...*/ } class Bar : Foo { new public static void Do() { /*...*/ } /*...*/ } 

Let me make a further change:

class Foo { public void Do() { /*...*/ } /*...*/ } class Bar : Foo {      new public static void Do()      { new Bar().Do();/*...*/ } /*...*/  } 

This does not compile:

‘Error CS0176: Member ‘Bar.Do()’ cannot be accessed with an instance reference; qualify it with a type name instead.’

So, I lose access to my inherited method via an instance reference from a static method!

What would be the logic behind it? Or did I make a typo somewhere?

I came across this when I was trying to define a static method ‘Show’ for my form derived from ‘Form’.

  • 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. 2026-05-11T13:19:50+00:00Added an answer on May 11, 2026 at 1:19 pm

    Where do you think the bug is? The fact that there is a warning is absolutely right. From the C# 3.0 spec, section 10.3.4:

    A class-member-declaration is permitted to declare a member with the same name or signature as an inherited member. When this occurs, the derived class member is said to hide the base class member. Hiding an inherited member is not considered an error, but it does cause the compiler to issue a warning. To suppress the warning, the declaration of the derived class member can include a new modifier to indicate that the derived member is intended to hide the base member.

    The fact that your method invocation fails is subtler, but it’s basically because the member lookup algorithm picks the static method, and then this part of section 7.5.5.1 is used:

    Final validation of the chosen best method is performed:

    The method is validated in the context of the method group: If the best method is a static method, the method group must have resulted from a simple-name or a member-access through a type. If the best method is an instance method, the method group must have resulted from a simple-name, a member-access through a variable or value, or a base-access. If neither of these requirements is true, a compile-time error occurs.

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

Sidebar

Ask A Question

Stats

  • Questions 117k
  • Answers 118k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

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

    • 7 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer class Program { static void Main(string[] args) { Timer timer… May 11, 2026 at 10:50 pm
  • Editorial Team
    Editorial Team added an answer Use GROUP_CONCAT SELECT GROUP_CONCAT(bar) FROM TABLE GROUP BY foo; May 11, 2026 at 10:50 pm
  • Editorial Team
    Editorial Team added an answer Your code doesn't work because the function is not returning… May 11, 2026 at 10:50 pm

Related Questions

I have the following model : class Model extends BaseModel { public function save($conn
I want to know if it is possible to let compiler issue a warning/error
I had the following C++ code, where the argument to my constructor in the
I've run across an interesting PHP/SOAP error that has me stymied. After searching I

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.