Can any one let me know "How to access base class variables in derived class"?
Example:
Class 1.cs Code
public class baseClass
{
public int intF = 0, intS = 0;
public int addNo()
{
int intReturn = 0;
intReturn = intF + intS;
return intReturn;
}
}
Public class child : baseClass
{
public int add()
{
int intReturn = 0;
intReturn = base.intF * base.intS;
return intReturn;
}
}
Class2.cs Code
class Program
{
static void Main(string[] args)
{
baseClass obj = new baseClass();
obj.intF = 5;
obj.intS = 4;
child obj1 = new child();
Console.WriteLine(Convert.ToString(obj.addNo()));
Console.WriteLine(Convert.ToString(obj1.add()));
Console.ReadLine();
}
}
The problem is in child class which gets inherited from base class..
The value of intF and intS is always showing as 0 instead of 5&4.
Can any one let me know where I am going wrong?
Regards,
G.V.N.Sandeep