Monday 15 July 2013

c# - Method Overloading or method overriding? -


In my C # application, I have a base class, in which the function is a modulation. I am a derived class from the above base class Which includes the same work as the base class, is this concept correct implementation?

  Public square base class {Public Zero My Function () {Write the console row (""); }} Public Category DeriveClass: Base Class {Public Zero myFunction () {Console.WriteLine (""); }}   

I'm a newbie in programming, sorry for my english

You have actually done this way in BaseClass.MyFunction .

If you want to override correctly, you must declare the base version of the virtual (or summary ) and then override Public class base class {public virtual zero myFunction} {}} public class DerivedClass: baseclass {public override zero myFunction () {}}

Overloading and overriding are different things Override overloading shown above means that with many ways of the same name, , But different parameters like if you have these methods:

  Public Zero My Function (Int I) {} Public Zero My Function (Decimal D) {}  < / Pre> 

You will say that there are two overload of MyFunction there.

No comments:

Post a Comment