Click here to Skip to main content
15,889,931 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
Hi,

I've two classes in my program. In my first.class I defined some value in variables, see code below:
var x= System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();
var y= Path.GetFileName(x);

MessageBox.show(x);



How can I use those values in in my second.class ??


Thanks in advance
Posted
Updated 12-Apr-11 4:51am
v2

If those values are something that most of the classes in your application will use, then these must be a part of a base class and all the classes must inherit from it.

If not, then make it public static property and other classes can use them.
 
Share this answer
 
lets assume your first class name is first, all you have to do is to declare those variables as public
and call them using first.x and first.y
 
Share this answer
 
v3
Create an Instance of first.class in second.class and use the properties of first.class in second.class
 
Share this answer
 
Comments
Member 7762422 12-Apr-11 10:59am    
Thanks all for the solutions! Web Work, I needed to create an Instance in my situation THANKS!
web works 12-Apr-11 11:12am    
Good. You are welcome !!

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