Suppose I my project contains a Form and a Class. I would like to create a variable that can be accessed by both the Form and the class. In VB6 I could create a public variable in the (module / class), and easily access it like so:
VB6 Example
[Module code]
Public string_name as string
[/Module code]
[Form Code]
string_name = "test data"
MsgBox(string_name) ' Returns "test data"
[/Form Code]
How could I produce the above functionality with C#? I’m assuming I’d have to create a public class, but I’m not sure of the best way to declare public variables.
thank you,
Evan
You can do the same in c# (expose a field as public), though that is not good practice.
Use properties instead: