C# uses a semicolon (;) as a statement-termination character. Every statement in C# code
must end with this semicolon, except when you’re defining a block structure such as a
method, a conditional statement, or a looping construct. By omitting this semicolon, you can
easily split a statement of code over multiple physical lines. You just need to remember to put
the semicolon at the end of the last line, to end the statement.
The following code snippet demonstrates four equivalent ways to perform the same operation
(adding three numbers together):
in whatever way you want. The general rule of thumb is to make your code as readable
as possible. Thus, if you have a long statement, spread the statement over several lines so it’s
easier to read. On the other hand, if you have a complex code statement that performs several
operations at once, you can spread the statement over several lines or separate your logic into
multiple code statements to make it clearer.
must end with this semicolon, except when you’re defining a block structure such as a
method, a conditional statement, or a looping construct. By omitting this semicolon, you can
easily split a statement of code over multiple physical lines. You just need to remember to put
the semicolon at the end of the last line, to end the statement.
The following code snippet demonstrates four equivalent ways to perform the same operation
(adding three numbers together):
// A code statement split over two lines. myValue = myValue1 + myValue2 + myValue3; // A code statement split over three lines. myValue = myValue1 + myValue2 + myValue3; // A code statement on a single line. myValue = myValue1 + myValue2 + myValue3; // Two code statements in a row. myValue = myValue1 + myValue2; myValue = myValue + myValue3;As you can see in this example, C# gives you a wide range of freedom to split your statement
in whatever way you want. The general rule of thumb is to make your code as readable
as possible. Thus, if you have a long statement, spread the statement over several lines so it’s
easier to read. On the other hand, if you have a complex code statement that performs several
operations at once, you can spread the statement over several lines or separate your logic into
multiple code statements to make it clearer.
Tags:
asp.net