Public Variables

Teaboy

New member
Joined
Aug 11, 2005
Messages
2
Im making the switch from VB.NET to C#, and Ive found it pretty easy so far, except for public variables.

In VB.NET, my startup class would be something like this...

Code:
Public Class clsCore

Public O as clsOptions

...

End Class

In C#, I tried

Code:
	public class clsCore
	{

		public clsOptions O;
        ...

        }

But that gives me:
clsCore.cs(45): An object reference is required for the nonstatic field, method, or property Project.clsCore.O

How do I go about doing it?
 
You will find that your Main method is probably marked as static (the equivalent of shared in VB) - that means it cannot access any instance members from the class.

You are probably better of treating your Main routine as a a kind of bootstrapper to your program - give the clsCore class a method that is your real startup logic and in the Main create an instance of clsCore and call this method.
 
Back
Top