Click here to Skip to main content
15,905,316 members
Home / Discussions / C#
   

C#

 
NewsMessage Closed Pin
8-Apr-14 22:06
cpquest8-Apr-14 22:06 
GeneralMessage Removed Pin
8-Apr-14 23:09
mveRichard MacCutchan8-Apr-14 23:09 
QuestionSet or get the background color NavBar Control of DevExpress ? Pin
Member 24584678-Apr-14 19:53
Member 24584678-Apr-14 19:53 
AnswerRe: Set or get the background color NavBar Control of DevExpress ? Pin
BillWoodruff9-Apr-14 0:10
professionalBillWoodruff9-Apr-14 0:10 
QuestionError webBrowser c# Pin
william ormundo8-Apr-14 4:42
william ormundo8-Apr-14 4:42 
AnswerRe: Error webBrowser c# Pin
Dave Kreskowiak8-Apr-14 4:47
mveDave Kreskowiak8-Apr-14 4:47 
GeneralRe: Error webBrowser c# Pin
william ormundo8-Apr-14 4:57
william ormundo8-Apr-14 4:57 
GeneralRe: Error webBrowser c# Pin
Dave Kreskowiak8-Apr-14 5:08
mveDave Kreskowiak8-Apr-14 5:08 
GeneralRe: Error webBrowser c# Pin
william ormundo8-Apr-14 5:23
william ormundo8-Apr-14 5:23 
GeneralRe: Error webBrowser c# Pin
william ormundo8-Apr-14 5:49
william ormundo8-Apr-14 5:49 
QuestionIssue with Session Management Pin
Member 107334468-Apr-14 3:21
Member 107334468-Apr-14 3:21 
AnswerRe: Issue with Session Management Pin
Wes Aday8-Apr-14 4:16
professionalWes Aday8-Apr-14 4:16 
QuestionInvalidCastException while changing windows service startup type Pin
AshwiniSH7-Apr-14 21:26
professionalAshwiniSH7-Apr-14 21:26 
QuestionRe: InvalidCastException while changing windows service startup type Pin
Ravi Bhavnani8-Apr-14 4:39
professionalRavi Bhavnani8-Apr-14 4:39 
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 

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.