Page 35 - DCAP312_WEB_TECHNOLOGIES_II
P. 35
Unit 2: Introduction to C#
Comments Notes
Comments allow in order certification of source code. The C# compiler ignores explanation.
Three styles of comments are allowed in C#:
Single-line Comments
The “//” character progression marks the following text as a single-line comment. Single-line
comments, as one would expect, end at the first end-of-line following the “//” comment marker.
Multiple-line Comments
Comments can span multiple lines by using the multiple-line comment style. Such comments
start with “/*” and end with “*/”. The text between those multi-line comment markers is the
comment.
//This style of a comment is restricted to one line.
/*
This is another style of a comment.
It allows multiple lines.
*/
XML Documentation-line Comments
This comment is used to generate XML documentation. Each line of the comment begins with
“///”.
/// <summary> documentation here </summary>
This is the most recommended type. Avoid using butterfly style comments. For example:
//**************************
// Butterfly style documentation comments like this are not recommended.
//**************************
Case Sensitivity
C# is case-sensitive, including its variable and method names.
The variables myInteger and MyInteger below are distinct because C# is case-sensitive:
int myInteger = 3;
int MyInteger = 5;
The following code will generate a compiler error (unless a custom class or variable named
console has a method named writeline()):
// Compiler error!
Console.writeline(“Hello”);
The following corrected code compiles as expected because it uses the correct case:
Console.WriteLine(“Hello”);
2.1.2 Variables
Variables are used to store values. More officially, a variable binds an object (in the general sense
of the term, i.e. a specific value) to an identifier (the variable’s name) so that the entity can be
accessed later. Variables can, for example, store the value of user input:
string name = Console.ReadLine ();
LOVELY PROFESSIONAL UNIVERSITY 29