Click here to Skip to main content
15,892,768 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
i have 3 classes as follows.
C#
class a
{
   string access;
    
   public void setaccess(string c)
   {
      this.access = c;
   }
   public string getaccess()
   {
      return this.access;
   }
}

class b: a
{
   setaccess("test");
}
//Form class
class c
{
   a aa = new a();
   string bb = aa.getaccess();
   messagebox.show(bb);
}

i want the class b to update the value of variable "access" in class a and the updated value to be shown in class c. Right now when i run the application the messagebox is empty. Can anyone please help me. I can not figure out what am i doing wrong.
Posted
Updated 25-Feb-14 17:42pm
v2

Try this

C#
b aa = new b();
   string bb = aa.getaccess();
   messagebox.show(bb);
 
Share this answer
 
Comments
Zanem 26-Feb-14 0:18am    
Thanks Karthik it was so simple. :)
Karthik_Mahalingam 26-Feb-14 0:25am    
welcome :)
try this

C#
public class a
    {

        string access;

        public void setaccess(string c)
        {
            this.access = c;
        }

        public string getaccess()
        {
            return this.access;
        }

    }

    public class b : a
    {
        public b()
            : base()
        {
            setaccess("updated");
        }

    }

    //Form class
    public class c
    {

       
        public void test()
        {

            b aa = new b();
            string bb = aa.getaccess();
            messagebox.show(bb);
        }
    }
 
Share this answer
 
v2
Try This Code

C#
// Create b class object because your are setting values of class a var in b class
    public class c
    {
        public void test()
        {
            b aa = new b();
            string bb = aa.getaccess();
            messagebox.show(bb);
        }
    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900