Slightly random question, but does the ";" character come after everything but the method in C#? I'm assuming that there are exceptions, if someone could elaborate on this please, as well. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Slightly random question, but does the ";" character come after everything but the method in C#? I'm assuming that there are exceptions, if someone could elaborate on this please, as well.

When would one use the semicolon in C#?

22nd Aug 2016, 7:27 PM
Brian
Brian - avatar
8 Answers
+ 2
@Brian, "So, to clarify. The semicolon ( ; ) would be used everywhere, except after curly braces." That's not actually what Ajeet means. Ajeet means, you may use semicolons ; almost after every end of a statement except after a code block. By that, Ajeet does not mean that you may not use a semicolon after every curly brace { }. You may still use a semicolon after a curly brace as long as it is not a curly brace for code block. for example: new int[] { 1, 2, 3 }; you may still put a semicolon after a curly brace { }
23rd Aug 2016, 3:34 PM
Erwin Mesias
Erwin Mesias - avatar
+ 1
the semicolon represents the end of a statement in your code. Every statement will end with one, otherwise you will get a compile error. examples: int x = 45; x += 4; Console.WriteLine("Milk"); if (x == 49) { Console.WriteLine("it is 49"); } im still relatively new and not good at explaining but i hope it helps.
22nd Aug 2016, 8:12 PM
Jaylon Caldwell
Jaylon Caldwell - avatar
+ 1
Once you do actual programming, you'll understand why, and when semicolon (;) is used. Because your program will not run if you have missing semicolons. Maybe the main reason why your still unfamiliar with the usage of the semicolon is that your still not programming really. Try C# programming using Visual Studio, once you miss a semicolon, a colored (red) line will appear at the end of your statement indicating that you missed atnd you need to place a semicolon here. By using Visual Studio, you'll get to know more not only the things about semicolon but you'll also get a deeper understanding of the .NET Framework and the C# Language itself.
22nd Aug 2016, 9:01 PM
Erwin Mesias
Erwin Mesias - avatar
+ 1
you have to put ; everywhere except which is having {} code block..
23rd Aug 2016, 5:58 AM
Ajeet Dubey
Ajeet Dubey - avatar
+ 1
Ajeet, Thanks dude. Erwin, I'm familiar with coding. I was wondering about the syntax of the language itself, however, you are right using VS would be the right way to go as it would tell one with the intelisense function. Jaylon, Thanks. I get what you're saying there. So, to clarify. The semicolon ( ; ) would be used everywhere, except after curly braces.
23rd Aug 2016, 6:07 AM
Brian
Brian - avatar
+ 1
@Brian, Actually, there is no specific rule on how and when to use semicolons. The usage of semicolon varies per syntax. example: - In the systax in For Loop, there is a rule on where to put semicolons. - In the syntax for array declaration, there is a proper place where to put (;) - In the syntax for Do-While Loop, there is also a proper place for (;) But the General Rule on where to place a semicolon, there is no such thing buddy 👍
24th Aug 2016, 5:54 AM
Erwin Mesias
Erwin Mesias - avatar
0
@Erwin, that's what I was wondering. I should have phrased the question better. Is there no 'rule' to the semicolon? Syntactically speaking?
23rd Aug 2016, 9:32 PM
Brian
Brian - avatar
0
@Erwin, riiight.. Ok, cool. Thanks man, that actually answers my question. Thanks for getting back to me guys, much appreciated. Do any of you know of any good C# videos or comprehensive books? Similar to cbt nuggets?
24th Aug 2016, 8:51 PM
Brian
Brian - avatar