Click here to Skip to main content
15,886,110 members
Home / Discussions / C#
   

C#

 
GeneralRe: x86 and x64 in one project Pin
po_saa22-Jul-16 0:12
po_saa22-Jul-16 0:12 
GeneralRe: x86 and x64 in one project Pin
Rob Philpott21-Jul-16 23:48
Rob Philpott21-Jul-16 23:48 
GeneralRe: x86 and x64 in one project Pin
po_saa22-Jul-16 0:19
po_saa22-Jul-16 0:19 
QuestionInheritance Pin
sunsher20-Jul-16 15:11
sunsher20-Jul-16 15:11 
GeneralRe: Inheritance Pin
PIEBALDconsult20-Jul-16 16:47
mvePIEBALDconsult20-Jul-16 16:47 
AnswerRe: Inheritance Pin
BillWoodruff20-Jul-16 18:03
professionalBillWoodruff20-Jul-16 18:03 
AnswerRe: Inheritance Pin
Rob Philpott20-Jul-16 20:01
Rob Philpott20-Jul-16 20:01 
AnswerRe: Inheritance Pin
OriginalGriff20-Jul-16 20:20
mveOriginalGriff20-Jul-16 20:20 
Yes - that is exactly what inheritance and method overriding is all about!
C#
public class A : B
    {
    public void DoIt()
        {
        Console.WriteLine("A:DoIt");
        InB();
        }
    public override void Inner()
        {
        base.Inner();
        Console.WriteLine("A:Inner");
        }
    }
public class B
    {
    public void InB()
        {
        Console.WriteLine("B:InB");
        Inner();
        }
    public virtual void Inner()
        {
        Console.WriteLine("B:Innner");
        }
    }

Then when you create an instance:
C#
A a = new A();
a.DoIt();
You get:
A:DoIt
B:InB
B:Innner
A:Inner

Because B.Inner is marked as virtual it can be overridden in derived classed - as it is in A - and the system will look for the most "appropriate" version to call. Because a is declared as an instance of the A class, it calls the A version of the method.
If you declared a as a B instead but assigned it an A (which is perfectly fine as every A is a "superset" of B):
B b = new A();
b.Inner();

You can't call the DoIt method (because B doesn't contain a definition for DoIt), but you will still get:
B:Innner
A:Inner
Becuase the value inside the variable b is still an instance of the A class so the system calls the "latest" version.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

GeneralRe: Inheritance Pin
sunsher27-Jul-16 12:48
sunsher27-Jul-16 12:48 
GeneralRe: Inheritance Pin
OriginalGriff27-Jul-16 19:20
mveOriginalGriff27-Jul-16 19:20 
Questionhow i can use Kinect to record skeleton tracking Pin
Member 1252528120-Jul-16 4:12
Member 1252528120-Jul-16 4:12 
AnswerRe: how i can use Kinect to record skeleton tracking Pin
Dave Kreskowiak20-Jul-16 8:14
mveDave Kreskowiak20-Jul-16 8:14 
QuestionInconsistent synchronization Pin
Bernhard Hiller19-Jul-16 22:29
Bernhard Hiller19-Jul-16 22:29 
AnswerRe: Inconsistent synchronization Pin
User 1106097919-Jul-16 23:31
User 1106097919-Jul-16 23:31 
GeneralRe: Inconsistent synchronization Pin
Bernhard Hiller19-Jul-16 23:59
Bernhard Hiller19-Jul-16 23:59 
GeneralRe: Inconsistent synchronization Pin
User 1106097920-Jul-16 0:02
User 1106097920-Jul-16 0:02 
GeneralRe: Inconsistent synchronization Pin
Bernhard Hiller20-Jul-16 0:18
Bernhard Hiller20-Jul-16 0:18 
GeneralRe: Inconsistent synchronization Pin
User 1106097920-Jul-16 0:25
User 1106097920-Jul-16 0:25 
GeneralRe: Inconsistent synchronization Pin
User 1106097920-Jul-16 9:22
User 1106097920-Jul-16 9:22 
AnswerRe: Inconsistent synchronization Pin
Pete O'Hanlon20-Jul-16 0:38
mvePete O'Hanlon20-Jul-16 0:38 
QuestionRe: Inconsistent synchronization Pin
User 1106097926-Jul-16 19:59
User 1106097926-Jul-16 19:59 
AnswerRe: Inconsistent synchronization Pin
Bernhard Hiller26-Jul-16 21:32
Bernhard Hiller26-Jul-16 21:32 
GeneralRe: Inconsistent synchronization Pin
User 1106097926-Jul-16 21:42
User 1106097926-Jul-16 21:42 
GeneralRe: Inconsistent synchronization Pin
Bernhard Hiller26-Jul-16 21:53
Bernhard Hiller26-Jul-16 21:53 
PraiseRe: Inconsistent synchronization Pin
User 1106097926-Jul-16 22:17
User 1106097926-Jul-16 22:17 

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.