Only Assignment, Call, increment....

Nate Bross

Contributor
Joined
Apr 6, 2005
Messages
601
Location
Chicago, IL
I have an object (sprite) and I have a method called inkCF, or incriment current frame.

C#:
        public void inkCF()
        {
            if ((iCurrentFrame + 1)< (iNumFrames))
            {
                iCurrentFrame += 1;
            }
            else
            {
                iCurrentFrame = 1;
            }

        }

My issue is that when I try to call the method, either of these two ways

C#:
MyClass x;
x.inkCF;

//Or, This, inside of another sub in the class

code...
inkCF;
code....

I get the following error

Only assignment, call, increment, decrement, and new object expressions can be used as a statement.

When I used the MSDN help it didn't really help me. I'm new to C#, and the same method worked in Visual Basic without error.

Using.....C# 2005
 
If I paste the code in the inkCF method inline with the rest of the code it works fine, but I don't want to do that because I need to call that method from several places....
 
I believe the problem is that you are missing the parens when you call the method:

C#:
MyClass x;
x.inkCF();
 
code...
inkCF();
code....
If I recall, parenthesis are optional for methods without arguments in Visual Basic. That could easily be causing the confusion, esspecially if the code was originally written in VB. Parenthisis are always required in C#.
 
Thanks a million, that was it. I could have sworn that I tried that, but in hindsight I tried so many combonations that I may have had seporate error.

Regardless I added the () and it works now.
 
Yeah, I always get a little frazzled when switching between languages (do I need the semi-colon? and so on). I'm glad it turned out to be something simple.
 
Back
Top