Jump to content
  • Advertisement
Sign in to follow this  
da_cobra

C# using structs

This topic is 4126 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I'm rather new to the C# language, but I know C++. Now I came upon a problem when using a struct and I can't seem to figure it out for the moment : I want to create a highscore table (I just started writing the code, so I do not have much for now).
public int NewHighscoreTable(string strDefaultName, long lDefaultScore, long lDefaultLowerScore)
        {
            FileStream fs = File.Create("highscore.dat"); 

            struct highscoreLine
            {
                public string strName;
                public int iScore;
            }

            highscoreLine hl = new highscoreLine(); 

            return 0;
        }

When I execute this code I get the following errors : Error 1 } expected => points to the semicolon (;) right after the FileStream line Error 2 Invalid token 'return' in class, struct, or interface member declaration Error 3 Type or namespace definition, or end-of-file expected When I comment out the whole struct lines, then the errors are gone and I can execute my code with no problem. Am I missing something here?!?

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
You can't declare a struct within a method.

Share this post


Link to post
Share on other sites
Maybe try to declare the struct outside of the method?
I'm not sure if you can declare a struct/class inside a method (that is, a local struct/class). You can in C++, but I don't know about C#.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!