Introductory C#
Introductory C#
What is C#?
Basic Features of C#
• Compiled language (code is compiled into Intermediate Language (IL) and run
by the .NET runtime).
C# Syntax Basics
class Program {
}
• using System; → Imports the System namespace (needed for
Console.WriteLine).
• static void Main() → The main method, the entry point of C# programs.
Comments in C#
/*
This is a
multi-line comment
*/
int 25 4 bytes
using System;
class Program {
}
• Console.Write("text") → Prints text (without newline).
Operators in C#
+ a+b Addition
- a-b Subtraction
* a*b Multiplication
/ a/b Division
% a%b Modulus
== a == b Equal to
!= a != b Not equal
Conditional Statements
} else {
Loops in C#
For Loop
}
While Loop
int count = 0;
Console.WriteLine(count);
count++;
Functions in C#
using System;
class Program {
Console.WriteLine("Hello!");
}
Function with Parameters & Return Value
using System;
class Program {
return a + b;
Arrays in C#
csharp
CopyEdit
Console.WriteLine(numbers[0]); // Output: 10
using System;
class Car {
Console.WriteLine("Beep! Beep!");
}
}
class Program {
Console.WriteLine(myCar.brand);
myCar.Honk();
}
• Class → Defines a blueprint.
using System;
class Program {
int a = Convert.ToInt32(Console.ReadLine());
int b = Convert.ToInt32(Console.ReadLine());