Click here to Skip to main content
15,896,453 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I have two classes ..I want to use an integer variable in Class x and use that in Class y.please suggest how to do tat.

VB
Public Class x

dim abc as integer = 1

End class


VB
Public class y

Dim test as integer = 0

If ( test = abc)

End class
Posted
Updated 5-Jun-13 20:11pm
v2

To make a member accessible, make it friend (internal in C#). To also make it accessible between different assemblies, make it public.

Please see also: http://msdn.microsoft.com/en-us/library/76453kax.aspx[^].

—SA
 
Share this answer
 
Comments
Abhinav S 6-Jun-13 2:16am    
5. Or one could use properties to expose values across classes.
Sergey Alexandrovich Kryukov 6-Jun-13 2:21am    
Thank you, Abhinav.

This is a good point. I just answered in a most general way. But of course, it is usually recommended, for better maintainability of code, to expose only some properties and methods, keeping all fields private. Thank you for reminding me.

—SA
Maciej Los 6-Jun-13 2:19am    
+5
Sergey Alexandrovich Kryukov 6-Jun-13 2:21am    
Thank you, Maciej.
—SA
You can use properties to expose values in one class and use them in the other.
You will need instances of these classes in this case.
 
Share this answer
 
Comments
Maciej Los 6-Jun-13 2:19am    
+5
Abhinav S 6-Jun-13 2:53am    
Thank you.
 
Share this answer
 
v2
Comments
Abhinav S 6-Jun-13 2:53am    
5.
Maciej Los 6-Jun-13 3:42am    
Thank you, Abhinav ;)

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