i want to call a varible from parent class to base using inhertance in c#.net i please give immedate replay......Tha nk You
calling a variable from parent class to base class
Collapse
X
-
Tags: None
-
Originally posted by Ranjith Reddy Bandii want to call a varible from parent class to base using inhertance in c#.net i please give immedate replay......Tha nk You
A parent class is a base class.
If you want to use a method from the class you inherit from, use the base keyword.
I think your going to have to re-word your question
-mwalts -
Hi,
Yes in C# you can get any public member of parent class by using keyword "base"
Like here is scenario
[code=c]
public class MyParent
{
public string parentString;
public MyParent() {
Console.WriteLi ne("Parent Constructor.");
}
public MyParent(string myString)
{
parentString = myString;
Console.WriteLi ne(parentString );
}
public void print()
{
Console.WriteLi ne( "Iam parent; " + parentString);
}
}
Class myChild : MyParent
{
//Calling parent constructor
public MyChild() : base("From Derived")
{
Console.WriteLi ne("Child Constructor");
}
public new void print()
{
//here you call parent property /member using base
base.parentstri ng="munawar"
base.print();
Console.WriteLi ne("I'm a Child Class.");
}
}
public static void Main()
{
MyChild child = new MyChild();
child.print();
((MyChild)child ).print();
}
[/code]
Thanks
Munawar HussainComment
-
-
Comment