I’ve just started learning C# following a series of tutorials, and I decided to try writing something simple myself. Everything looks fine according to the tutorials and what I made while following them last night, but apparently there are multiple errors. Sometimes these errors seem to just fix themselves and I’ve no idea what changed, so it’s quite difficult to figure out what I’m doing right or wrong.
What I’ve written:
The errors I’m receiving:
EDIT: Not 100% sure how but I followed each commenters’ suggestion and somehow fixed it. Thanks for your help, any advice on how to avoid this in the future is welcome.
Don’t remove line 16. And the compiler doesn’t care about indentation.
Do you have other scripts? There are errors there from other classes.
Did you copy and paste this code in from your web browser? I’m wondering if a weird invisible character didn’t get picked up.
https://marketplace.visualstudio.com/items?itemName=nhoizey.gremlins This plugin might help if that’s the case.
Your error mentions ‘Invalid Token “Say Goodbye!”‘.
Where is this in your project? This seems like the issue is with another file or something, or we aren’t seeing the full file.
The code you have provided above is completely valid so is not the issue. You have another issue somewhere else.
Yeah originally the code was supposed to say ‘Say goodbye’ and the user would have to enter ‘Goodbye’. For some reason the program was insisting the string variable ‘goodBye’ was still there, even though I’d gotten rid of it. That error seemed to have gone away on its own somehow. You can see why I’m so confused.
can you compiled c# in VS code ?
I had missed the curly brace at the end of line 12. Move that symbol to the next line, which is the expected formatting for C#. Fix the indentation everywhere, as that is making this difficult to read. Use the auto-formatter tool at Edit > Advanced > Format Document.
remove line 16. Fix the indentation on lines 9 to 14. Needs one more tab.
Thanks! I’ve done that, now the only error I receive is on line 15: } expected [First VS Project, First VS Project, First VS Project]csharp(CS1513)
(I called the project ‘First VS Project’)
C# devs
null reference exceptions