Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am facing a problem in my project, i have a getter and setter property in one partial class and i want access that in another class(aspx.cs file).

The partial class is a library class file the structure is like this

C#
public partial class OneClass
{
        private int a;

        public int A
        {
            get{ return a; }
            set { a = value; }
        }
}


and in another class TwoClass i want to access the public property of Class OneClass. The problem is TwoClass cannot inherit from OneClass.

Please help me to solve the issue, Thanks in advance!!
Posted
Updated 9-Apr-12 19:25pm
v2

Is the class TwoClass part of the same assembly? If yes, then just create an object of it and you can access the property using the object. Something luke this -
C#
TwoClass objTwoClass = new TwoClass();
//to get value of A
int ValueOfA = objTwoClass.A;
//to set the value of A
objTwoClass.A = 1; //or any int value


I didn't get this point in your question - "The problem is TwoClass cannot inherit from OneClass."? AFAIK, the partial classes can be inherited.
 
Share this answer
 
You can access public properties of OneClass in TwoClass if you can able to access the related OneClass object in TwoClass. And this you can do (if you ignore inheritance as option) by either
1. passing the OneClass object to TwoClass or
2. by having it as TwoClass member and filling it at appropriate time.
 
Share this answer
 
Comments
Suraj S Koneri 10-Apr-12 1:48am    
But we cannot create objects for the OneClass since it is partial class.

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