Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Suppose I declare a class. and I create a object of that class. now I create a another class. now I want to pass 1st class object to the 2nd class for accessing the all properties of the ist class from 2nd class..
so how do I do..
Posted

C#
Class1 obj1 = new Class1();
Class2 obj2 = new Class2();
obj2.process(obj1);

obj2 now has access to all public methods and properties of obj1.

Note: I am not sure that this is what you are asking, so you may need to add some more detail to your question.
 
Share this answer
 
You can either declare all properties of your first class as public, or use reflection in your second class to access any non-public properties of your first class.
 
Share this answer
 
You can use it by using the constructor.
First create the constructor to this object.

Class1 obj1 = new Class1();
Class2 obj2 = new Class2(obj1);
 
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