Teaboy Posted September 4, 2005 Posted September 4, 2005 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? Quote
Administrators PlausiblyDamp Posted September 4, 2005 Administrators Posted September 4, 2005 Which line are you getting the error on? Also how and where is clsOptions declared? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Teaboy Posted September 4, 2005 Author Posted September 4, 2005 In my Main() I've got O = new clsOptions(); and that's giving me the error. Quote
Administrators PlausiblyDamp Posted September 4, 2005 Administrators Posted September 4, 2005 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. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.