Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I'm making the switch from VB.NET to C#, and I've found it pretty easy so far, except for public variables.

 

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

 

Public Class clsCore

Public O as clsOptions

...

End Class

 

In C#, I tried

 

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?

  • Administrators
Posted

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.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...