inh I can't get the value of property of base class in c#(inheritance)
-
hi, Actually,I have a base class say A and its derived class B.I have created an object of B and assigned the properties of both A and B classes.But When I use the properties of base class ,i couldn't get it? regards, Bill
Please show us the code. Did you check the Access Modifier Properly ?
Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you. View My Latest Article
-
hi, Actually,I have a base class say A and its derived class B.I have created an object of B and assigned the properties of both A and B classes.But When I use the properties of base class ,i couldn't get it? regards, Bill
-
hi, Actually,I have a base class say A and its derived class B.I have created an object of B and assigned the properties of both A and B classes.But When I use the properties of base class ,i couldn't get it? regards, Bill
use
base
keyword to access all the base class variables.Abhishek Sur My Latest Articles Working with Excel using MDAC
Basics on LINQ and Lambda Expressions
Create .NET Templates -
Please show us the code. Did you check the Access Modifier Properly ?
Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you. View My Latest Article
class AA { public AA{} private decimal _a; public decimal A{ get { return _a; } set { _deno = a; } } } classs BB:AA { public BB{} private decimal _b; public decimal B{ get { return _b; } set { _deno = b; } } public B Getval() { BB b=new BB(); b.A=5; b.B=1; } } class CC { public CC{} public void Test() { BB b=new BB(); b=b.Getval(); decimal aa=b.A; decimal bb=b.B; } } The problem is that aa is not being initialize.
-
class AA { public AA{} private decimal _a; public decimal A{ get { return _a; } set { _deno = a; } } } classs BB:AA { public BB{} private decimal _b; public decimal B{ get { return _b; } set { _deno = b; } } public B Getval() { BB b=new BB(); b.A=5; b.B=1; } } class CC { public CC{} public void Test() { BB b=new BB(); b=b.Getval(); decimal aa=b.A; decimal bb=b.B; } } The problem is that aa is not being initialize.
billcodes wrote:
public B Getval()
There is no type called B. What makes you think there is ? It would help if you told us the exact error message, and the line that generates it, but at first glance, I think this is your problem. Your other problem is that this is the ASP.NET forum, which this question has NOTHING to do with, in any form. Pls use the C# forum in future.
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
-
class AA { public AA{} private decimal _a; public decimal A{ get { return _a; } set { _deno = a; } } } classs BB:AA { public BB{} private decimal _b; public decimal B{ get { return _b; } set { _deno = b; } } public B Getval() { BB b=new BB(); b.A=5; b.B=1; } } class CC { public CC{} public void Test() { BB b=new BB(); b=b.Getval(); decimal aa=b.A; decimal bb=b.B; } } The problem is that aa is not being initialize.
billcodes wrote:
public B Getval() { BB b=new BB(); b.A=5; b.B=1; }
You also don't return anything. I *think* you wanted to write public BB Getval() { BB b=new BB(); b.A=5; b.B=1; return b; } It's unusual for a non static method to return an instance of a class, I need to create a BB to call Getval, and get another BB.
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
-
class AA { public AA{} private decimal _a; public decimal A{ get { return _a; } set { _deno = a; } } } classs BB:AA { public BB{} private decimal _b; public decimal B{ get { return _b; } set { _deno = b; } } public B Getval() { BB b=new BB(); b.A=5; b.B=1; } } class CC { public CC{} public void Test() { BB b=new BB(); b=b.Getval(); decimal aa=b.A; decimal bb=b.B; } } The problem is that aa is not being initialize.
Your propertys are completely wrong. You're trying to return _a but when you're setting the property you set _deno to a. Try this
class AA
{
public AA{}
private decimal _a;
public decimal A{ get { return _a; } set { _a = value; } }}