.NET

C#, dotNet Core, ASP.NET, Entity Framework, testing, architecture, and everything .NET developers need.

Filtering, Ordering, and Projecting with LINQ

Get what you want from your data

LINQ makes it easy to select, sort, and shape your data. ๐Ÿ”Ž Filtering with Where 1 var even = numbers.Where(n => n % 2 == 0); ๐Ÿ—‚๏ธ Ordering with OrderBy / OrderByDescending 1 2 var sorted = na...

Introduction to LINQ

Query data easily in C#

LINQ (Language Integrated Query) lets you work with data (like arrays and lists) using simple, readable queries. ๐Ÿ“ Why Use LINQ? Write less code to filter, sort, and search data. Works with ...

Working with Databases Using ADO.NET

Connect your C# app to SQL Server

ADO.NET is the standard way to connect your C# applications to relational databases like SQL Server. ๐Ÿ”Œ Connecting to SQL Server Youโ€™ll need a connection string (ask your DBA or use SQL Server Exp...

File and Directory Operations Recap

What youโ€™ve learned so far

Letโ€™s review what youโ€™ve learned about files and directories in C#. ๐Ÿ“„ File Operations Write to file: File.WriteAllText("a.txt", "Hello") Read from file: File.ReadAllText("a.txt") Write mul...

Working with Directories

Creating and managing folders in C#

Folders are called directories in C#. You can create, list, and delete them with a few commands. ๐Ÿ“‚ Create a Directory 1 Directory.CreateDirectory("myfolder"); ๐Ÿ—‚๏ธ List Files and Directories 1 2...

Streams and File I/O: Advanced

More control over file reading and writing

Streams give you fine control over reading and writing data, especially large files. ๐Ÿ“ค Writing with FileStream 1 2 3 4 5 using (FileStream fs = new FileStream("data.bin", FileMode.Create)) { ...

File I/O Basics

Reading and writing files in C#

C# makes it easy to work with files: reading, writing, and creating them on your system. ๐Ÿ“ Writing to a File 1 2 3 using System.IO; File.WriteAllText("hello.txt", "Hello, file!"); ๐Ÿ“– Reading fr...

Exception Best Practices

How (and when) to use exceptions in C#

Exceptions are powerful, but you should use them wisely. โœ… Best Practices Use exceptions for exceptional cases only. Donโ€™t use them for normal control flow. Catch only what you ...

Custom Exception Classes

Make your own error types

C# lets you create your own exception classes for specific error types. ๐Ÿ› ๏ธ Defining a Custom Exception 1 2 3 4 class NegativeNumberException : Exception { public NegativeNumberException(strin...

Throwing Exceptions

How to signal errors in your own code

Sometimes, your code needs to tell the user โ€œsomething went wrong.โ€ You do this by throwing exceptions. ๐Ÿ—๏ธ Throwing an Exception 1 2 3 4 5 6 void Divide(int a, int b) { if (b == 0) th...