Click here to Skip to main content
15,896,118 members
Home / Discussions / C#
   

C#

 
Questionunable to start debugging Pin
arulbaskar7-Apr-14 3:54
arulbaskar7-Apr-14 3:54 
AnswerRe: unable to start debugging Pin
OriginalGriff7-Apr-14 4:38
mveOriginalGriff7-Apr-14 4:38 
AnswerRe: unable to start debugging Pin
ZurdoDev7-Apr-14 8:47
professionalZurdoDev7-Apr-14 8:47 
Questionc# get method object by address from C++ program Pin
Lord Baaleos7-Apr-14 0:45
Lord Baaleos7-Apr-14 0:45 
AnswerRe: c# get method object by address from C++ program Pin
Richard Deeming7-Apr-14 2:07
mveRichard Deeming7-Apr-14 2:07 
AnswerRe: c# get method object by address from C++ program Pin
BobJanova7-Apr-14 2:57
BobJanova7-Apr-14 2:57 
QuestionAdvantages of using virtual method in base class? Pin
Varun Thakur7-Apr-14 0:01
Varun Thakur7-Apr-14 0:01 
AnswerRe: Advantages of using virtual method in base class? PinPopular
OriginalGriff7-Apr-14 0:37
mveOriginalGriff7-Apr-14 0:37 
Simple: if you specify virtual when your base class creates a method, then it can (but doesn't have to be) overridden in the derived class.

Lets take an example: a Fruit class.
If you create a virtual Peel method which uses a knife to cut away the peel, you can override it in your derived Apple class to use an apple peeler - because it does a better job. And in your Orange class to just use your fingers.
But in all cases, you just call the Peel method from other code and it doesn't need to worry about which actual method is used. Just as if I threw you a paper bag containing a piece of fruit and told you to "peel that". You would open the bag, and decide on the best method to use to do it - knife, peeler or fingers - as a result of which fruit you found: A Mango would need a knife, an Apple a peeler, and an Orange your fingers.

When you use virtual in your base class, the system will use the most-derived version:
C#
public class Fruit
    {
    public virtual void Peel(){Console.WriteLine("Knife");}
    }
public class Orange : Fruit
    {
    public override void Peel()
        {
        Console.WriteLine("Fingers");
        }
    }
public class Apple : Fruit
    {
    public override void Peel()
        {
        Console.WriteLine("Peeler");
        }
    }
public class Mango : Fruit
    {
    }

And so
C#
Orange o = new Orange();
Apple a = new Apple();
Mango m = new Mango();
Fruit f = new Fruit();
o.Peel();
a.Peel();
m.Peel();
f.Peel();
f = o;
f.Peel();
Will give you:
VB
Fingers
Peeler
Knife
Knife
Fingers
Without you having to look at what type of Fruit it is and calling the appropriate Peel method yourself.
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)

GeneralRe: Advantages of using virtual method in base class? Pin
Varun Thakur7-Apr-14 18:48
Varun Thakur7-Apr-14 18:48 
AnswerRe: Advantages of using virtual method in base class? Pin
pallelokanathareddy8-Apr-14 6:43
professionalpallelokanathareddy8-Apr-14 6:43 
QuestionHow to merger data from two sql databases that have a same structure ? Pin
taibc6-Apr-14 23:59
taibc6-Apr-14 23:59 
AnswerRe: How to merger data from two sql databases that have a same structure ? Pin
Peter Leow7-Apr-14 0:08
professionalPeter Leow7-Apr-14 0:08 
Questiondatagridview doesn´t show the datasource Pin
tom_ma6-Apr-14 21:40
tom_ma6-Apr-14 21:40 
AnswerRe: datagridview doesn´t show the datasource Pin
V.6-Apr-14 22:13
professionalV.6-Apr-14 22:13 
GeneralRe: datagridview doesn´t show the datasource Pin
tom_ma6-Apr-14 22:34
tom_ma6-Apr-14 22:34 
GeneralRe: datagridview doesn´t show the datasource Pin
V.6-Apr-14 22:45
professionalV.6-Apr-14 22:45 
GeneralRe: datagridview doesn´t show the datasource Pin
tom_ma7-Apr-14 0:24
tom_ma7-Apr-14 0:24 
GeneralRe: datagridview doesn´t show the datasource Pin
V.7-Apr-14 1:19
professionalV.7-Apr-14 1:19 
GeneralRe: datagridview doesn´t show the datasource Pin
tom_ma7-Apr-14 0:24
tom_ma7-Apr-14 0:24 
AnswerRe: datagridview doesn´t show the datasource Pin
OriginalGriff6-Apr-14 22:27
mveOriginalGriff6-Apr-14 22:27 
GeneralRe: datagridview doesn´t show the datasource Pin
tom_ma6-Apr-14 22:38
tom_ma6-Apr-14 22:38 
GeneralRe: datagridview doesn´t show the datasource Pin
OriginalGriff6-Apr-14 23:00
mveOriginalGriff6-Apr-14 23:00 
GeneralRe: datagridview doesn´t show the datasource Pin
tom_ma6-Apr-14 23:08
tom_ma6-Apr-14 23:08 
GeneralRe: datagridview doesn´t show the datasource Pin
OriginalGriff6-Apr-14 23:24
mveOriginalGriff6-Apr-14 23:24 
GeneralRe: datagridview doesn´t show the datasource Pin
tom_ma7-Apr-14 0:14
tom_ma7-Apr-14 0:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.