Click here to Skip to main content
11,496,146 members (1,377 online)
The site is currently in read-only mode for maintenance. Posting of new items will be available again shortly.
See more: C#
how call function (method) in class parent in child class?
Posted 3-Mar-12 3:07am
Edited 3-Mar-12 3:24am
SAKryukov at 3-Mar-12 19:23pm
What do you mean as child and parent? If could be nested classes, composition... what?
Some code sample, please.
And what is the problem. Just call it... Access? Understanding of types and members, instance vs. static? What?
You need a reference to the parent class of course. Without a MUCH better description, we can't help much beyond that.

Based on what you are asking (it wasn't very clear but I will give it a bash), you will be looking at a scenario like this:
public class MyParentClass
    public virtual void SomeMethod()
        /* do parent class stuff here */
public class MyChildClass : MyParentClass
    public override void SomeMethod()
        /* do child class stuff here */
        base.SomeMethod(); // <--- This will call the parent class method

At any point in the overridden method in the child class you can call "base.SomeMethod()".

Hope that helps Smile | :) ...
ghahreman sayyali at 4-Mar-12 11:00am
very thanks
nortee at 4-Mar-12 12:00pm
Glad to have helped :)
If you want to call a none static method of the parent in a child class, the method must be public or protected:


If you want to call a none static method of the child in a parent class:
you have to have an instance of the child class and the method must be a public method:

ChildClass instance = new ChildClass();


(new ChildClass()).MethodName();

It's better If you explain why do you want to do so.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Dnyaneshwar@Pune 692
1 RyanDev 230
2 CHill60 208
3 Sascha Lefèvre 195
4 Sergey Alexandrovich Kryukov 124
0 Sergey Alexandrovich Kryukov 10,401
1 OriginalGriff 8,910
2 Sascha Lefèvre 3,899
3 Maciej Los 3,422
4 Richard Deeming 2,600

Advertise | Privacy | Mobile
Web01 | 2.8.150520.1 | Last Updated 3 Mar 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100