So far as i see in c#,

virtual function are not only for polymorphism,

it's also for overriding the hiding method warning through the compiler

shall we be held right ?

i'll give a good example :

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

now , im using B x = new B(); therefore the compiler will warn me for method at school B hides the main one inside a. so there's 2 solutions :

1) mark the main one in B using the New keyword

2) result in the one out of 'A' virtual and also the one out of B - Overriding - this can obvious the warning of hiding..

the only real difference is going to be with Polymorphism A x = new B();

if you will see 'new' at school B - always the main one from the is going to be known as while if im while using virtual and not the brand new mechanism - the main one from B is going to be known as.

so virtual has 2 roles insinternet : (please correct me if im wrong)

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

2) not to mention overriding the functions in yes-polymorphism enviroment.

please correct me if im wrong.

No, virtual techniques are for polymorphism. Your "solution" #2 can change the behavior of calling x.func() from calling the A implementation to calling the B implementation - i.e. which makes it polymorphic. Yes, it removes the warning - but it is no more a "non-polymorphism atmosphere" as is available made the behavior polymorphic. Did for you to do that, or otherwise? Should you did, then virtual and override is what you want. Should you did not, you need to use new or relabel the technique.

I'd strongly counsel you to prevent using method hiding unless of course you will need to. Would you even need B to be a consequence of A? If you wish to provide permanently with similar title but another meaning, think about making them separate classes. Personally I avoid inheritance unless of course there is a obvious polymorphic relationship.

(Observe that overriding and over-loading will vary concepts, incidentally. You mean overriding here.)

The compiler warning is simply that. It is a warning that the implementation of func() is most likely incorrect, since it is hiding the member make up the base class.

It's effect would be to take away the warning, but that is not its reason. The reason is to help you double-check and ensure your intention.

Essentially "New" keyword can be used to beat the warning of hiding method. while virtual key phrase is purely for that polymorphism it informs the compiler if override version from the method available then run that method other smart run virtual method.

Virtual overriding can also be known as runtime polymorphism.since it establishes runtime that what method is going to be run.

While "New" keyword take away the warning and just run child class method and hides parents method ,to over come this we use:

   public new void Method()
{
//Some code
Base.Method();

}

applying this we run parent method and unhide parents class method