Chapter 2 2 min read
Save

C# Programming Fundamentals

DotNet Technology · BCA · Updated Apr 23, 2026

Table of Contents

C# Programming Fundamentals

C# (pronounced C-sharp) is a modern, object-oriented programming language developed by Microsoft as part of the .NET initiative. It combines the power of C++ with the simplicity of Visual Basic and is the primary language for .NET development.

Program Structure

A C# program consists of namespaces, classes, and methods. The entry point is the Main method. A minimal program: using System; class Program { static void Main() { Console.WriteLine("Hello"); } }. C# is case-sensitive, and every statement ends with a semicolon.

Data Types

C# has value types (stored on the stack) and reference types (stored on the heap). Value types include int, float, double, char, bool, decimal, and struct. Reference types include string, object, arrays, and classes. The var keyword enables implicit typing.

Operators and Expressions

C# supports arithmetic (+, -, *, /, %), relational (==, !=, <, >), logical (&&, ||, !), bitwise, assignment, and ternary (?:) operators. The ?? null-coalescing operator and ?. null-conditional operator handle null values safely.

Control Flow

Conditional statements include if-else and switch. Loops include for, while, do-while, and foreach (for iterating collections). break exits a loop; continue skips to the next iteration. Pattern matching in switch was enhanced in later C# versions.

Methods

Methods are blocks of code that perform a task. They have a return type, name, and parameters. Parameters can be passed by value (default), by reference (ref), as output (out), or as parameter arrays (params). Method overloading allows multiple methods with the same name but different signatures.

Arrays and Strings

Arrays are fixed-size collections: int[] arr = new int[5];. Multi-dimensional arrays (int[,]) and jagged arrays (int[][]) are supported. Strings are immutable; the StringBuilder class provides mutable string operations. String interpolation ($"Hello {name}") simplifies formatting.

Exception Handling

C# uses try-catch-finally blocks. try contains code that may throw exceptions; catch handles specific exception types; finally executes regardless of exceptions (for cleanup). Custom exceptions inherit from Exception. The throw keyword raises exceptions.

Summary

C# fundamentals include data types, operators, control flow, methods, arrays, strings, and exception handling. Mastering these basics is essential before advancing to object-oriented programming and .NET frameworks.

Related Notes

Discussion

0 comments

Join the discussion

Log in to share your thoughts and help fellow students.

Log in to comment

No comments yet. Be the first to share your thoughts!