|
-
Feb 6th, 2006, 06:18 PM
#1
Thread Starter
Fanatic Member
Method problem.
I have no idea what's going on, when I try to run ANY method in a console application, I get some weird error saying "An object reference is required for the nonstatic field, method, or property" what does that mean? If I run this method in an application with a form, it works fine.
Thanks,
Sir Loin
-
Feb 6th, 2006, 06:25 PM
#2
Re: Method problem.
It means that you are calling a method without creating an instance of the class. It may be that you are using 'this' to refer to the current instance. In a WinForms app that's fine as your code is likely to be in a form. In a console app there are no forms so you cannot use 'this' unless you do so inside a class definition.
-
Feb 6th, 2006, 06:27 PM
#3
Thread Starter
Fanatic Member
Re: Method problem.
Oh, thanks. I'll have to read more tutorials. I might just give up on C# and go back to C++, C++ seems easier. lol
Thanks,
Sir Loin
-
Feb 6th, 2006, 06:38 PM
#4
Re: Method problem.
 Originally Posted by Sir Loin
Oh, thanks. I'll have to read more tutorials. I might just give up on C# and go back to C++, C++ seems easier. lol
Thanks,
Sir Loin
I assure you that it is not. All else being equal, C# is definitely easier to come to grips with than C++. Of course, if you're already relatively fluent in C++ then it will of course be easier to use than an unfamiliar language. C# is like the good parts of VB and C++ combined.
As for the issue that you're having at the moment, that's just straight OOP. You have to have an instance to refer to an instance member. That would be the same in C++.
-
Feb 6th, 2006, 06:41 PM
#5
Fanatic Member
Re: Method problem.
I realize you dont want to post all of your code, but a piece of it plus your namespace USING list, would help a bit.
And somehow I cant see someone mastering C/C++ failing at C#.
-
Feb 6th, 2006, 08:13 PM
#6
Re: Method problem.
 Originally Posted by Sir Loin
Oh, thanks. I'll have to read more tutorials. I might just give up on C# and go back to C++, C++ seems easier. lol
While many will disagree, I do find C++'s console capabilities nicer and possibly easier to use than C#'s.
Saying that, your problem is an issue with using OOP. Everything in C# is within a Class. Main() is a static method so if you don't declare your methods static, you'll need to create an instance of that class before referencing the methods.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|