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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:46:45+00:00 2026-05-23T23:46:45+00:00

As far as i see in c#, virtual function are not just for polymorphism,

  • 0

As far as i see in c#,

virtual function are not just for polymorphism,

it is also for overriding the hiding method warning by the compiler

am i right ?

i will give an example :

class A
{
   public void func(int a)
     {
        ....
     }
}
class B:A
{
   public void func(int a)
     {
        ....
     }
}

now , im using B x = new B();
so the compiler will warn me for method in class B hides the one in A.
so there is 2 solutions :

1) mark the one in B with the New keyword

2) make the one in 'A' virtual and the one in B - Overriding – this will clear the warning of hiding..

the only difference will be with Polymorphism A x = new B();

if there will be ‘new’ in class B – always the one from A will be called while if im using the virtual and not the new mechanism – the one from B will be called.

so virtual has 2 roles in .net : (please correct me if im wrong)

1) resolve the hiding warning (in non-Polymorphism enviroment)

2) and of course overriding the functions in yes-polymorphism enviroment.

please correct me if im wrong.

  • 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-23T23:46:45+00:00Added an answer on May 23, 2026 at 11:46 pm

    No, virtual methods are for polymorphism. Your “solution” #2 will change the behaviour of calling x.func() from calling the A implementation to calling the B implementation – i.e. making it polymorphic. Yes, it removes the warning – but it’s no longer a “non-polymorphism environment” as you’ve made the behaviour polymorphic. Did you want to do that, or not? If you did, then virtual and override is the way to go. If you didn’t, you should use new or rename the method.

    I would strongly advise you to avoid using method hiding unless you really need to. Do you even need B to derive from A? If you want to give it another method with the same name but a different meaning, consider making them separate classes. Personally I steer away from inheritance unless there’s a clear polymorphic relationship.

    (Note that overriding and overloading are different concepts, by the way. You mean overriding here.)

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

Sidebar

Related Questions

As far as I can see Solutions Architect is just a different marketing term
As far as I see, git pull someRemote master tries to merge the remote
For fun I am trying to see how far I can get at implementing
I'm slowly learning Objective-C and Cocoa, and the only way I see so far
What do you see as benefits for one over the other? As far as
Thanks for the contributions so far - I can see now that $rowq is
Everytime I load my model into XNA, I can usually see it far off
This link seems to suggest that it just works: (pretty far on the bottom
I need to call a const function from a non-const object. See example struct
most of my application will not look so well on landscape, but that's the

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.