01_C_fundamentals
01_C_fundamentals
What is C#?
• Types of comments:
• Single line comments (// )
• Multiline comments (/* …. …. … */)
Main returning a value
• Static variables
• Declared at the class level
• Arithmetic operators
• Relational operators
• Logical operators
• Increment and decrement
• Conditional operators
Arithmetic operators
Relational operators
if (boolean-expression)
{
statement block
}
statement
If flowchart
If … else statement
• Extension of if statement
• General form
if (boolean-expression)
{
True block statement
}
else
{
False block statement
}
If… else flowchart
Nesting if…else statement
Switch statement
Initialization
While(test-condition)
{
body of the loop
}
While loop - example
Do… While loop
Initialization;
do
{
body of the loop
} while(test-condition);
Do… While loop - example
For loop
• Is an entry-controlled loop
• Syntax:
for(initialization;testcondition;increment)
{
Body of the loop…..
}
objectName.MethodName(parameters);
Method invoking - example
Static method invoking - example
Method parameters
• Value parameters
• Reference paramaters
• Output parameters
Value parameters
• Declaration of arrays
Example: int[] counter;
• Creation of arrays
Example: counter = new int[5];
• Combination
Example: int[] counter = new int[5];
• Initialization of arrays
Example: counter[0] = 10;
counter[1] = 2;
Int[] counter = {10, 2, 5};
Two dimension arrays
• Example:
List<string> cities = new List<string>();
• Private
Member is accessible only from the class containing the member
• Public
Member is accessible from anywhere outside the class as well. Also
accessible in derived class.
• Protected
Member is accessible only to its own class and in derived class.
• Internal
Member is available within the assembly or component that is being
created but not to the clients of that component.
Objects
class Abc
{
static Abc()
{
…….
}
}
The “this” reference
• This refers to the object that called the method
• Used to distinguish between local and instance variables that have the same
name
• Example:
class Example
{
int x;
int y;
public void SetXY(int x, int y)
{
this.x = x;
this.y = y;
}
}
Constant members