Click here to Skip to main content
16,012,223 members
Home / Discussions / C#
   

C#

 
GeneralRe: richtextbox.lines problem Pin
bfis10813725-May-10 8:49
bfis10813725-May-10 8:49 
GeneralRe: richtextbox.lines problem Pin
Luc Pattyn25-May-10 9:13
sitebuilderLuc Pattyn25-May-10 9:13 
GeneralRe: richtextbox.lines problem Pin
bfis10813725-May-10 9:21
bfis10813725-May-10 9:21 
AnswerRe: richtextbox.lines problem Pin
Dr.Walt Fair, PE25-May-10 9:38
professionalDr.Walt Fair, PE25-May-10 9:38 
GeneralRe: richtextbox.lines problem Pin
Luc Pattyn25-May-10 9:55
sitebuilderLuc Pattyn25-May-10 9:55 
QuestionTabPage invisible Pin
jojoba201125-May-10 5:43
jojoba201125-May-10 5:43 
AnswerRe: TabPage invisible Pin
Abhinav S25-May-10 5:52
Abhinav S25-May-10 5:52 
QuestionAccessing methods of a derived class (polymorphism) Pin
Neo1010125-May-10 5:22
Neo1010125-May-10 5:22 
Hello

Can one access methods of a derived class?
e.g.:
public class GameObject { ... }
public class Chest : GameObject
{
    public void OpenChest();
    public void CloseChest();
}

GameObject chest = new Chest();
chest.OpenChest(); // Does not work because .OpenChest() doesn't appear


It seems the only GameObject members that appear are those from the base class GameObject.
The methods from Chest are apparently not accessible by polymorphism context.
You can only access Chest's methods by explicitly casting my GameObject type (chest)
to a Chest type, i.e.:
(Chest)chest; chest.OpenChest(); // should work now?


Is there any other way to do this other than casting it explicitly to a Chest type?
I would like to know the reasons why the compiler works this way.

Thank you.
AnswerRe: Accessing methods of a derived class (polymorphism) Pin
OriginalGriff25-May-10 5:32
mveOriginalGriff25-May-10 5:32 
AnswerRe: Accessing methods of a derived class (polymorphism) Pin
Abhinav S25-May-10 5:33
Abhinav S25-May-10 5:33 
AnswerRe: Accessing methods of a derived class (polymorphism) Pin
AspDotNetDev25-May-10 10:40
protectorAspDotNetDev25-May-10 10:40 
GeneralRe: Accessing methods of a derived class (polymorphism) Pin
Neo1010125-May-10 22:02
Neo1010125-May-10 22:02 
GeneralRe: Accessing methods of a derived class (polymorphism) Pin
AspDotNetDev25-May-10 23:09
protectorAspDotNetDev25-May-10 23:09 
GeneralRe: Accessing methods of a derived class (polymorphism) Pin
OriginalGriff25-May-10 23:41
mveOriginalGriff25-May-10 23:41 
AnswerRe: Accessing methods of a derived class (polymorphism) Pin
Bernhard Hiller25-May-10 21:59
Bernhard Hiller25-May-10 21:59 
GeneralRe: Accessing methods of a derived class (polymorphism) Pin
Neo1010125-May-10 22:08
Neo1010125-May-10 22:08 
GeneralRe: Accessing methods of a derived class (polymorphism) Pin
Bernhard Hiller27-May-10 0:17
Bernhard Hiller27-May-10 0:17 
QuestionArgumentOutOfRangeException (index not negative) on EndInvoke while calling asynchronious Pin
hoernchenmeister25-May-10 5:00
hoernchenmeister25-May-10 5:00 
AnswerRe: ArgumentOutOfRangeException (index not negative) on EndInvoke while calling asynchronious [modified] Pin
Alan N25-May-10 5:47
Alan N25-May-10 5:47 
GeneralRe: ArgumentOutOfRangeException (index not negative) on EndInvoke while calling asynchronious Pin
hoernchenmeister25-May-10 20:25
hoernchenmeister25-May-10 20:25 
QuestionError: Method Not found (using Invokemember) Pin
newbie_md25-May-10 4:36
newbie_md25-May-10 4:36 
AnswerRe: Error: Method Not found (using Invokemember) Pin
Alan N25-May-10 7:02
Alan N25-May-10 7:02 
QuestionObject Initializer?? Pin
AmbiguousName25-May-10 2:54
AmbiguousName25-May-10 2:54 
AnswerRe: Object Initializer?? Pin
Richard MacCutchan25-May-10 3:10
mveRichard MacCutchan25-May-10 3:10 
GeneralRe: Object Initializer?? Pin
David Skelly25-May-10 4:14
David Skelly25-May-10 4: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.