Sign in to follow this  
da_cobra

C# using structs

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this