Log In

Don't have an account? Sign up now

Lost Password?

Sign Up

Next

Module 1: Programming Fundamentals (C# Basics)

1. What is .NET & Why Enterprises Use It?

At its simplest, .NET (pronounced “dot net”) is a free, open-source, cross-platform developer platform for building many different types of applications. It provides a programming model, a comprehensive software library, and a runtime environment.

The Ecosystem Components

  • The Runtime: Think of this as the “engine.” It’s the virtual machine that manages the execution of programs (handling memory, security, and hardware interaction).
  • The Libraries: A massive collection of pre-written code (APIs) that developers use so they don’t have to “reinvent the wheel” for things like reading files, sending emails, or processing JSON.
  • The Languages: .NET supports C# (the most popular), F# (functional), and VB.NET (legacy).

Why Enterprises Choose .NET

Enterprises (large corporations) don’t just pick tools because they are “cool”; they pick them for stability and ROI (Return on Investment).

  • Security: It has built-in features to prevent common attacks like SQL injection and Cross-Site Scripting (XSS).
  • Scalability: It can handle millions of requests, which is why companies like UPS, Stack Overflow, and Microsoft use it.
  • Microsoft Support: Large companies feel safe knowing a trillion-dollar company is maintaining the ecosystem.
  • Productivity: With “NuGet” (the package manager) and powerful IDEs, developers can build complex systems much faster than in many other languages.

2. .NET Framework vs. .NET Core vs. .NET 8+

This is the most confusing part for beginners because of the naming history. Here is the breakdown:

Feature.NET Framework.NET Core.NET 5, 6, 7, 8+
Era2002 – 20192016 – 20202020 – Present
OSWindows OnlyWindows, macOS, LinuxCross-platform
StatusLegacy (Maintenance)Replaced by .NET 5+The Current Standard
PerformanceGoodExcellentTop-tier / Blazing Fast

Detailed Breakdown

  • .NET Framework: The original version. It’s tied to the Windows Operating System. If you are maintaining an old bank application built in 2010, you are likely using this.
  • .NET Core: A complete rewrite. Microsoft realized the world was moving to Linux servers and Cloud (AWS/Azure). They made it lightweight, modular, and fast.
  • .NET 5, 6, 7, 8+: Microsoft dropped the word “Core.” These versions represent the “Unity” of the platform. .NET 8 is a Long Term Support (LTS) version, meaning it is the most stable and recommended version for modern enterprise work today.

3. Setting Up: Visual Studio vs. VS Code

You need a place to write your code (an Integrated Development Environment or IDE).

Visual Studio (The “Heavyweight Champion”)

  • What it is: A full-featured IDE.
  • Best for: Large enterprise projects, complex debugging, and desktop (WPF/WinForms) apps.
  • Pros: It does everything for you. It has the best “intellisense” (code completion) and visual designers.
  • Cons: It’s a massive download (gigabytes) and can be slow on older computers.

VS Code (The “Lightweight Ninja”)

  • What it is: A code editor.
  • Best for: Web development, cross-platform work, and people who like a fast, minimalist interface.
  • Pros: Extremely fast, works on everything, and has a huge library of plugins.
  • Cons: You have to manually install extensions (like the “C# Dev Kit”) to make it work like a full IDE.

4. Writing Your First C# Program

Let’s look at the “Hello World” code and explain every single word, as this is where the magic starts.

C#

using System;

namespace HelloWorldApp
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello, World!");
        }
    }
}

Breaking Down the Terms:

  1. using System;: This is a Namespace Import. It tells the computer, “I want to use the standard ‘System’ library which contains basic functions like printing text.”
  2. namespace HelloWorldApp: This is a container used to organize your code. It prevents “name collisions” (e.g., if two people name a class “User”, the namespace keeps them separate).
  3. class Program: C# is an Object-Oriented language. Everything happens inside a class. Think of a class as a blueprint for a building.
  4. static: This means the method belongs to the class itself, not a specific “instance” of the class. You don’t need to “create” a program to run it.
  5. void: This is the Return Type. It means “this function does its job and returns nothing back.”
  6. Main: This is the Entry Point. When you click “Run,” the computer specifically looks for a folder called Main. If it doesn’t find it, the app won’t start.
  7. string[] args: This allows you to pass information into your app when you start it from a command line.
  8. Console.WriteLine: This is the command to print text to the screen.

How the Code Actually Runs

When you hit “Run,” a two-step process occurs:

  1. Compilation: Your C# code is turned into Intermediate Language (IL). It’s not quite machine code yet.
  2. JIT (Just-In-Time) Compilation: When the app runs, the CLR (Common Language Runtime) converts that IL into the specific machine code your CPU understands.

1. Variables & Data Types

In C#, a variable is a reserved memory location to store values. Because C# is a strongly typed language, you must tell the compiler exactly what kind of data you are storing.

Simple (Value) Types

These store the actual data in a part of memory called the Stack.

  • int: Stores whole numbers (integers) from -2.1 billion to +2.1 billion.
  • long: For much larger whole numbers (64-bit).
  • double / decimal: Used for fractional numbers. Tip: In enterprise finance apps, we use decimal because it has higher precision for money.
  • bool: Short for Boolean; stores only true or false.
  • char: Stores a single character, like 'A', wrapped in single quotes.

Complex (Reference) Types

These store a “pointer” to a location in a memory area called the Heap.

  • string: A sequence of characters, like "Hello", wrapped in double quotes.
  • object: The “Grandparent” of all types in .NET. It can hold anything, but it’s slower to use.

2. Operators & Expressions

Operators are symbols used to perform operations on variables.

  • Arithmetic Operators: +, -, *, /, and % (Modulus—returns the remainder of a division).
  • Comparison Operators: == (is equal to), != (not equal), >, <, >=, <=. These always result in a bool.
  • Logical Operators: * && (AND): True if both sides are true.
    • || (OR): True if at least one side is true.
    • ! (NOT): Reverses the result.
  • Assignment Operators: = (assigns a value), += (adds and assigns), ++ (increments by 1).

3. Conditional Statements (Control Flow)

Logic allows your program to make decisions. Without these, a program would just be a list of instructions running in a straight line.

If / Else If / Else

The most common way to branch logic.

C#

int age = 18;
if (age >= 21) {
    Console.WriteLine("Entry permitted.");
} else if (age >= 18) {
    Console.WriteLine("Entry permitted with restrictions.");
} else {
    Console.WriteLine("Entry denied.");
}

Switch Statement

Used when you have many fixed options for a single variable. It is cleaner and faster than writing ten if statements.

C#

string day = "Monday";
switch (day) {
    case "Monday": Console.WriteLine("Back to work!"); break;
    case "Friday": Console.WriteLine("Weekend is near!"); break;
    default: Console.WriteLine("Just another day."); break;
}

4. Loops (Iteration)

Loops allow you to repeat a block of code multiple times. This is essential for processing lists of data.

  • for Loop: Used when you know exactly how many times you want to repeat (e.g., “Do this 10 times”).C#for (int i = 0; i < 5; i++) { Console.WriteLine("Iteration: " + i); }
  • while Loop: Used when you don’t know how many times it will run; it keeps going as long as the condition is true.
  • do-while Loop: Similar to while, but it guarantees the code runs at least once before checking the condition.
  • foreach Loop: The “Enterprise King.” It is the safest and most readable way to go through every item in a collection (like a list of employees).

5. Console Applications

In the modern era of fancy web apps and mobile games, why do we start with Console Applications?

  1. Zero Distractions: There is no HTML, CSS, or UI logic. You focus 100% on the C# logic.
  2. The “Brains”: Most enterprise background tasks (Microservices, Web Jobs, Data Migrators) are essentially Console Apps that run on a server without a screen.
  3. Input/Output (I/O):
    • Console.WriteLine(): Sends data to the user.
    • Console.ReadLine(): Pauses the program and waits for the user to type something and hit Enter.

Putting it all together

Here is a “mini-program” using everything above:

C#

Console.WriteLine("Enter your score (0-100):");
string input = Console.ReadLine();
int score = int.Parse(input); // Converting string to number

if (score >= 50) {
    for (int i = 0; i < 3; i++) {
        Console.WriteLine("You Passed!");
    }
} else {
    Console.WriteLine("Try again next time.");
}

Leave a Comment

    🚀 Join Common Jobs Pro — Referrals & Profile Visibility Join Now ×
    🔥