Advanced Basics: LINQ, Nullables, Async Intro

You finished C# core. These 6 topics take you from "tutorial" to "job-ready". Every 2026 fresher interview asks 2-3 of these.

Read time: 12-15 mins. This makes 100% of quiz questions fair.

1. Null Handling: ? and ??

Problem: string name = null; int len = name.Length; โ†’ NullReferenceException crash.

int?Nullable int. Can be null. int? x = null; Valid. int x = null; Error.
?.Null-conditional. name?.Length returns null if name is null. No crash.
??Null-coalescing. int len = name?.Length ?? 0; If null, use 0.
string user = null;
int count = user?.Length ?? -1; // count = -1, no crash

2. LINQ Basics: Query Your Lists

LINQ = Language Integrated Query. Filter/transform lists without loops.

List<int> nums = new() {1,2,3,4,5};

// Old way: loop
List<int> evens = new();
foreach(var n in nums) if(n%2==0) evens.Add(n);

// LINQ way: 1 line
var evens = nums.Where(n => n % 2 == 0).ToList(); // [2,4]

// Common LINQ:
var squares = nums.Select(n => n*n).ToList();     // [1,4,9,16,25]
var sum = nums.Sum();                             // 15
var firstBig = nums.First(n => n > 3);            // 4

Rule: Use LINQ for List<T>. Reads like SQL. Asked in every interview.

3. using Statement: Auto-Cleanup

Files, DB connections must be closed. using calls Dispose() automatically, even if error.

// Old: try-finally
FileStream fs = File.OpenRead("a.txt");
try { /* read */ }
finally { fs.Dispose(); }

// New: using - same result, cleaner
using var fs = File.OpenRead("a.txt");
// fs.Dispose() called automatically at end of scope

Use for: File, HttpClient, SqlConnection, StreamReader. Prevents memory leaks.

4. params Keyword: Variable Arguments

Method accepts any number of parameters.

int Sum(params int[] numbers) {
    return numbers.Sum(); // LINQ!
}

Sum(1, 2);        // 3
Sum(1, 2, 3, 4);  // 10
Sum();            // 0

Rule: params must be last parameter. Console.WriteLine uses it.

5. async/await Intro: Don't Block

Problem: Downloading file freezes UI for 5 seconds.

// BAD: Blocks thread. UI freezes
string data = httpClient.GetString(url); // 5 sec wait

// GOOD: async - releases thread while waiting
async Task<string> GetDataAsync() {
    string data = await httpClient.GetStringAsync(url); // Thread free during 5 sec
    return data;
}

Key: await = "pause here, let other work happen". UI stays responsive. Server handles 1000s of users.
Interview line: "async/await prevents thread blocking. Use for I/O: files, network, DB."

6. var Rules + Expression-bodied Members

var rules:

var x = 5;      // OK: compiler sees 5 = int
var y = null;   // ERROR: null has no type. Use string y = null;
var z;          // ERROR: must initialize

Expression-bodied: Shorthand => for 1-line methods.

// Old:
int Square(int x) { return x * x; }

// New:
int Square(int x) => x * x;

public string Name { get; set; }
public int Age => DateTime.Now.Year - BirthYear; // Read-only property

โœ… You're Now Job-Ready

You just learned the 6 topics that separate "tutorial finisher" from "hireable fresher". Every question in the Mega Quiz and Interview Q&A is now fair game. You covered it all.

Next: Take the Final Recap Quiz to prove it.

Comments on Advanced Basics: LINQ, Nullables, Async Intro (0)

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