What is the use of Base keyword
hi friends please tell me the use of Base keyword
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jignesh TrivediPosted Jul 9, 2013, 10:56 PM
hi,
The "base" keyword is used to access members of the base class from the derived class in c#.
please refer
http://msdn.microsoft.com/en-us/library/hfw7t1ce(v=vs.71).aspx
hope this will help you.
Posted Jul 9, 2013, 2:52 PM
http://www.dotnetperls.com/base
VulpesPosted Jul 9, 2013, 2:28 PM
1. To call a base class constructor from a derived class constructor.
2. To call a base class method which is overridden in the derived class.
This simple program illustrates both uses:
The output is:
Sanjeeb LenkaPosted Jul 9, 2013, 2:16 PM
First the values are received by the derived class constructor and then passed to the base class constructor.
See The Code class A
{
int i;
A(int n, int m)
{
x = n;
y = m
Console.WriteLine("n="+x+"m="+y);
}
}
class B:A
{
int i;
B(int a, int b):base(a,b)//calling base class constructor and passing value
{
base.i = a;//passing value to base class field
i = b;
}
public void Show()
{
Console.WriteLine("Derived class i="+i);
Console.WriteLine("Base class i="+base.i);
}
}
class MainClass
{
static void Main(string args[])
{
B b=new B(7,8);//passing value to derive class constructor
b.Show();
}
}
OUTPUT
n=7 m= 8
Derived class i=8
Base class i=7