2. WHAT IS THE BASIC C# SYNTAX?
BASIC C# SYNTAX:
•C# code is made of a series of statements where
each statement ends with a semicolon “;”
• C# code is organized in “blocks”, which may
contain any number of statements, and are
bounded by braces “{” and “}”
3. LAYOUT OF A BLOCK OF CODE IN C#
{
<code line 1, statement 1>;
<code line 2, statement 2>
<code line 3, statement
2>;
}
4. WHAT IS A COMMENT?
•A comment is a descriptive text added to a
code. It is not executed/run because it is not
really part of the program code.
•Examples:
/* This is a comment */
// This is a different sort of comment.
/// A special comment
5. WHAT ARE VARIABLES?
•Variables store data which can be used and
changed within a program; in C# they have to
be assigned a name and a type first before they
can be used in C#
•C# syntax for declaring variables merely
specifies the type and variable name:
<type> <name>;
6. EXAMPLES OF VARIABLES:
• Integer Types
Type Alias For Allowed Values
sbyte System.SByte Integer between −128 and 127
byte System.Byte Integer between 0 and 255
int System.Int32 Integer between −2147483648 and 2147483647
uint System.UInt32 Integer between 0 and 4294967295
long System.Int64 Integer between −9223372036854775808 and
9223372036854775807
ulong System.UInt64 Integer between 0 and 18446744073709551615
7. EXAMPLES OF VARIABLES:
• Floating Types
Type Alias For MIN/MAX Values
float System.Single 1.5 × 10−45 / 3.4 × 1038
double System.Double 5.0 × 10−324 / 1.7 × 10308
decimal System.Decimal 1.0 × 10−28 / 7.9 × 1028
• Text and Boolean Types
Type Alias For Allowed Values
char System.Char One Unicode character, stored as an integer
between 0 and 65535
bool System.Boolean Boolean value, true or false
string System.String A sequence of characters
8. HOW DO YOU NAME VARIABLES?
• The first character of a variable name must be either a
letter, an underscore character(_), or the at symbol
(@).
• Next characters may be letters, underscore characters,
or numbers.
• C# is case sensitive, so be careful and remember the
exact case used when you declare your variables.
9. WHAT ARE EXPRESSIONS?
• Basic building blocks of computation made by
combining variables and operators.
10. WHAT ARE OPERATORS?
•Symbols that tells the compiler to perform
specific mathematical or logical manipulations.
• TYPES OF OPERATORS:
• Arithmetic Operators
• Relational Operators
• Logical Operators
• Bitwise Operators
• Assignment Operators
• Miscellaneous Operators
11. WHAT ARE OPERATORS?
•Symbols that tells the compiler to perform
specific mathematical or logical manipulations.
• TYPES OF OPERATORS:
• Arithmetic Operators
• Relational Operators
• Logical Operators
• Bitwise Operators
• Assignment Operators
• Miscellaneous Operators
12. MATH OPERATORS:
Operat
Sample Result
or
+ var1 = var2 +
var3;
var1 is assigned the value that is the sum of var2 and var3
- var1 = var2 -
var3;
var1 is assigned the value that is the value of var3
subtracted from the value of var2
* var1 = var2 *
var3;
var1 is assigned the value that is the product of var2 and
var3.
/ var1 = var2 /
var3;
var1 is assigned the value that is the result of dividing var2
by var3
% var1 = var2 %
var3;
var1 is assigned the value that is the remainder when var2
is divided by var3
13. STRING CONCATENATION OPERATOR:
Operat
Sample Result
or
+ var1 = var2 +
var3;
var1 is assigned the value that is the concatenation
of the two strings stored in var2 and var3
INCREMENT AND DECREMENT OPERATORS:
Operat
Sample Result
or
++ var1 = ++var2;
var1 is assigned the value of var2 + 1. var2 is increased by
var1 = var2++; 1
-- var1 = --var2; var1 is assigned the value of var2 - 1. var2 is decreased by
var1 = var2--; 1
14. ASSIGNMENT OPERATORS:
Operat
Sample Result
or
= var1 = var2; var1 is assigned the value of var2
+= var1 += var2; var1 is assigned the value that is the sum ofvar1 and var2
-= var1 -= var2; var1 is assigned the value that is the value of var2
subtracted from the value of var1.
*= var1 *= var2; var1 is assigned the value that is the product of var1 and
var2.
/= var1 /= var2; var1 is assigned the value that is the concatenation
of the two strings stored in var2 and var3.
%= var1 %= var2; var1 is assigned the value that is the remainder when var1
is divided by var2
15. ORDER OF OPERATORS:
Priority Operators
Highest ++, -- (used as prefixes); +, - (unary)
*, /, %
+, -
=, *=, /=, %=, +=, -=
Lowest ++, -- (used as suffixes)
16. SOURCES
• "Tutorials Point." C# Tutorial. N.p., n.d. Web. 20 Nov. 2014.
• "Variables." The Complete C# Tutorial. N.p., n.d. Web. 20 Nov.
2014.
• "C# Programming." Wikibooks. N.p., n.d. Web. 20 Nov. 2014.
• Watson, Karli, Jacob Vibe Hammer, John D. Reid, Morgan
Skinner, Daniel Kemper, and Christian Nagel. Beginning Visual
C#® 2012 Programming. Indianapolis: John Wiley and Sons,
2013. Print.