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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 9, 2013, 10:16 AM EDT
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
VulpesRank #55 · 29.2K reputationPosted Jul 9, 2013, 10:28 AM EDT
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:
Posted Jul 9, 2013, 10:52 AM EDT
http://www.dotnetperls.com/base
Jignesh TrivediRank #16 · 50.3K reputationPosted Jul 9, 2013, 6:56 PM EDT
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.