C# M1 – Basic Concepts
• C# is an object-oriented language for building secure and robust applications on the .NET
Framework.
• .NET Framework has two parts:
• Common Language Runtime (CLR): Handles memory management, code execution,
and accuracy.
• Class Library: Provides reusable classes for tasks like data handling, file access, and
text operations.
• Variables: Store data in memory; declared with a name and data type. Examples:
• int (whole numbers), float (decimals), double (larger decimals), char (single
character), bool (True/False), string (text).
• Printing:
• Console.Write() prints on the same line.
• Console.WriteLine() prints and moves to the next line.
• User Input: Console.ReadLine() reads input as string; can be converted using
Convert.ToInt32, Convert.ToDouble, etc.
• Comments:
• // for single-line, /* ... */ for multi-line.
• var Keyword: Lets compiler decide the variable type automatically (implicit typing).
• Constants: Declared with const, values cannot change (e.g., Pi, days of the week).
• Operators:
• Arithmetic: + - * / %.
• Precedence: Parentheses > Multiplication/Division > Addition/Subtraction.
• Assignment: =, +=, -=, etc.
• Increment/Decrement: ++ and --, with prefix and postfix forms.
Review: This module builds the foundation of C# by teaching how to store, display, and
manipulate data, which is the basis of all programs.
C# M2 – Conditionals and Loops
• if Statement: Executes code if condition is true.
• else Clause: Executes when condition is false.
• Nested if-else: Allows multiple conditions inside each other.
• if-else-if: For checking three or more possible actions.
• switch Statement: Tests a variable against multiple values (cases).
• Requires break to stop execution.
• default case runs if no other case matches.
• Loops:
• while loop: Runs while condition is true.
• for loop: Uses counter variable, condition, increment.
• do-while loop: Executes at least once before checking condition.
• break: Stops loop or switch immediately.
• continue: Skips current loop iteration and moves to next.
• Logical Operators:
• && (AND) – True only if all are true.
• || (OR) – True if at least one is true.
• ! (NOT) – Reverses a Boolean value.
•Conditional Operator (?:): Shorthand for if-else.
Review: This module teaches how programs make decisions and repeat actions, which
is key for problem-solving and automation in coding.
C# M3 – Methods
• Methods: Group of statements performing a task; can be predefined or user-made.
• Advantages:
• Code reusability, easy testing, modifiability, and input versatility.
• Declaring Methods: Needs return type, method name, and optional parameters.
• Calling Methods: Use method name with arguments.
• Parameters (Arguments): Variables that accept values when method is called.
• Multiple Parameters: Separated by commas; increases versatility.
• Optional Arguments: Default values can be given; can be overridden.
• Named Arguments: Call method parameters by name for clarity.
• Passing Arguments:
• By value (copies value).
• By reference (ref keyword, copies address).
• By output (out keyword, sends result out).
• Method Overloading: Same method name but different parameters.
• Recursion: Method calls itself until base case is met.
Review: This module highlights methods as building blocks of C#, promoting reusable,
cleaner, and more powerful code structures.
C# M4 – Classes and Objects
• Class: Blueprint for objects; defines variables and methods.
• Object: Instance of a class; real representation in the program.
• Value Types: Stored in stack; memory is fixed (e.g., int, char).
• Reference Types: Stored in heap; used for objects; memory address stored in stack.
• Encapsulation (Information Hiding): Combines members in a class and restricts access.
• Benefits: Data security, flexibility, code isolation.
• Access Modifiers:
• public – Accessible everywhere.
• private – Accessible only within class.
• protected – Accessible in class and derived classes.
• Constructors: Special methods run when object is created. Same name as class, no return
type. Can have parameters.
• Properties: Allow controlled access to private fields.
• Use get (read) and set (write).
• Can be auto-implemented for quick use.
Review: This module introduces object-oriented concepts, showing how classes and
objects make code structured, secure, and reusable.
C# M5 – Arrays and Strings
• Arrays:
• Store collection of same type values.
• Declared with type + [].
• Instantiated with new keyword and size.
• Follow zero-indexing (first element = index 0).
• Values can be assigned one by one or with { } initialization.
• Access elements using [index].
• Arrays in Loops: Easily processed using for or foreach.
• Multidimensional Arrays: Arrays with more than one dimension (like tables/matrices).
• Array Properties & Methods:
• .Length – Number of elements.
• .Rank – Number of dimensions.
• .Min(), .Max(), .Sum() – Find min, max, and sum.
• Strings: Objects of type String, not just characters.
• String Properties & Methods:
• .Length – Number of characters.
• .IndexOf() – Finds index of first occurrence of a value.
• .Insert() – Adds text at index.
• .Remove() – Deletes characters starting at index.
• .Replace() – Replaces one value with another.
• .Substring() – Extracts part of a string.
• .Contains() – Returns true if string has a value.