Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. inh I can't get the value of property of base class in c#(inheritance)

inh I can't get the value of property of base class in c#(inheritance)

Scheduled Pinned Locked Moved ASP.NET
csharpoopquestion
8 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    billcodes
    wrote on last edited by
    #1

    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

    A C A 3 Replies Last reply
    0
    • B billcodes

      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

      A Offline
      A Offline
      Abhijit Jana
      wrote on last edited by
      #2

      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

      B 1 Reply Last reply
      0
      • B billcodes

        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

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        I guess you meant to post this in the C# or VB.NET forum ?

        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.

        1 Reply Last reply
        0
        • B billcodes

          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

          A Offline
          A Offline
          Abhishek Sur
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • A Abhijit Jana

            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

            B Offline
            B Offline
            billcodes
            wrote on last edited by
            #5

            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.

            C D 3 Replies Last reply
            0
            • B billcodes

              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.

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              • B billcodes

                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.

                C Offline
                C Offline
                Christian Graus
                wrote on last edited by
                #7

                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.

                1 Reply Last reply
                0
                • B billcodes

                  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.

                  D Offline
                  D Offline
                  DoctorMick
                  wrote on last edited by
                  #8

                  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; } }

                  }

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups