c# help

Started by
6 comments, last by ckopins 11 years, 4 months ago
hi guys i need some help whenever i compile code like this it comes up with random errors and i followed the book of ron pentons properly

class lexington
{
weapon = lazarus revolver
armor = military uni
level = 70
}

now i get these errors
; needed
undeclared variable which is strange because i have declared it

thanks :)
Advertisement
At a glance, I notice several things:

-Each statement needs a semicolon (;) after it
-Not having semicolons will screw up the rest of your code that comes after where it ought to be
-Individual variables cannot be separate words like "lazarus revolver"
-The variable types in the code are not declared

I suspect that there are more issues as well, but it's hard to say for certain what they would be based on this fragment of code alone. If you post more code I'll be able to help you more, and I don't want to make guesses about what you're doing based on this alone. But from what's already here, I think that you may want to spend some more time practicing C# syntax before tackling something game-sized.

I think it's unlikely that you're following Ron Penton's book correctly, given that code formatted as above will never compile in C#. As a good general rule, remember that errors aren't random. They always represent problems in your underlying code, and they contain highly relevant information (even if the relevance isn't clear).

-------R.I.P.-------

Selective Quote

~Too Late - Too Soon~

The post above is 100% correct, you really need to take the time to learn C# and it's syntax before going any further.

As for your code, I believe something along the lines of the following is what you were actually trying to achieve:


class Lexington
{
private String weapon = "lazarus revolver";
private String armor = "military uni";
private int level = 70;
}

i followed the book of ron pentons properly

No, no you didn't.

I'm seriously having a "not sure if trolling" moment here. At any rate, the other posters have hit the nail on the head: you're not using correct C# syntax at all. Look at adt7's code, then look at your book again, and notice the things you left out.

Hazard Pay :: FPS/RTS in SharpDX (gathering dust, retained for... historical purposes)
DeviantArt :: Because right-brain needs love too (also pretty neglected these days)

could someone take a look at my code and please give me a few pointers thanks
i didnt mean to troll
I don't think that you're trolling. But you are being awfully vague in what sorts of "pointers" you're looking for. Based only on the code you posted above, the best advice I can give is to read up on C# syntax. MSDN has some great intro material that is free, though it can be a lot to absorb. I'd give a link, but I'm posting from my phone. I'll edit the link in when I get home. You can also post more code, so that we can get an idea of what you're trying to accomplish.

If you post back with a description of what you want the code fragment you posted to do, I can tell you how I might approach it.

EDIT: Added link to MSDN

-------R.I.P.-------

Selective Quote

~Too Late - Too Soon~

thanks khaiy :)
Some advice and Im not sure if this can be repeated enough, learn c# syntax. What you originally had written looked sudo and nothing resembling c#. Before continueing in your book check out this site, this guy has released 200 c# videos that do a great job teaching almost everything you need to know. http://thenewboston.org/list.php?cat=15

This topic is closed to new replies.

Advertisement