C#
Completed
-
Section 1: Getting Started
-
Section 2: Core Syntax
-
Section 3: Object-Oriented C#
-
Section 4: Working with Data
-
Section 5: Error Handling
-
Section 6: Delegates and Events
-
Section 7: Async Programming
-
Section 8: More Language Features
-
Section 9: File I/O and Serialization
-
Section 10: Networking in .NET
-
Section 11: The .NET Ecosystem
-
Section 12: Memory and Performance
-
Section 13: Concurrency Beyond Async
-
Section 14: Reflection and Attributes
-
Section 15: Testing and Best Practices
-
Section 16: Design Patterns in C#
-
Section 17: Standard Library Deep Dive
-
Section 18: Data Structures and Algorithms in C#
-
Section 19: GUI and Desktop Development Overview
-
Section 20: Practical Projects
-
Section 21: More Practice Exercises
-
Section 22: More Standard Library and Text Processing
-
Section 23: More Design Patterns
-
Section 24: More Projects
-
Section 25: Interview Practice
-
Section 26: C# Keywords Reference (Modifiers)
-
Section 27: C# Keywords Reference (Statements)
-
Section 28: C# Keywords Reference (Operators)
-
Section 29: BCL: System.Collections.Generic
-
Section 30: BCL: System.Linq
-
Section 31: BCL: System.Threading
-
Section 32: BCL: System.IO
-
Section 33: BCL: System.Text and System.Text.Json
-
Section 34: BCL: System.Net.Http
-
Section 35: C# Language Specification Topics
-
Section 36: More Practice Exercises
-
Section 37: More Async Patterns
-
Section 38: More BCL: System.Reflection and System.Diagnostics
-
Section 39: Nullable Reference Types In Depth
-
Section 40: C# Records and Pattern Matching In Depth
-
Section 41: Dependency Injection Deep Dive
-
Section 42: More Interview and Whiteboard Practice
77: NuGet Package Management
I've noticed a recurring theme with developers moving into C#: they often treat NuGet as if it's just a convenient "DLL downloader." They think of it like a digital filing cabinet where they go to grab a library, drop it into their project, and forget about it. But that's a dangerous way to look at it.
"NuGet is just a way to get DLLs" vs "NuGet manages a dependency graph"
If NuGet were just about downloading files, you'd just be copying .dll files into a /lib folder like we did in the early 2000s. The reality is that NuGet manages a dependency graph. When you install a package, you aren't just getting one piece of code; you're often getting a chain of other packages that the first one relies on.
Take a common example: let's say you install a high-level library for handling complex API requests. That library might depend on Newtonsoft.Json for serialization, which in turn might depend on a specific version of a system utility library. If you try to manually manage these, you'll eventually hit "Dependency Hell"—where Package A requires Version 1.0 of a library, but Package B requires Version 2.0. NuGet handles this resolution for you, deciding which version to actually ship in your build so the app doesn't crash at runtime with a MethodNotFoundException.
"Adding more packages is free" vs "The cost of transitive dependencies"
I've seen junior devs add a massive library like AutoMapper or Entity Framework just to use one single helper method. It feels "free" because the IDE handles the installation in seconds. But it isn't free. Every package you add increases your attack surface for security vulnerabilities and bloats your final binary size.
You need to look at the transitive dependencies. When you add one package, look at your .csproj file or the "Dependencies" node in your Solution Explorer. If adding one small utility brings in fifteen other libraries you didn't ask for, ask yourself: "Do I actually need this, or can I write these ten lines of code myself?" I usually lean toward writing it myself if the dependency chain is too deep. It keeps the project lean and makes updates much less painful.
"The GUI is the only way" vs "The power of the CLI and .csproj"
The NuGet Package Manager UI in Visual Studio is great for browsing, but if you want to be an efficient engineer, you need to get comfortable with the dotnet add package command and the .csproj file itself. The UI hides the "truth" of your project.
When you install a package via the CLI, you're modifying your project file. Take a look at a typical entry in your .csproj:
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>
Because this is just XML, it lives in your version control (Git). This is why you should never check in your /bin or /obj folders. You don't check in the actual DLLs; you check in the instruction to download those DLLs. When your teammate pulls your code, NuGet reads that file and restores the exact versions needed. If you were just "downloading DLLs," you'd be bloating your Git repo with binary files, which is a cardinal sin in professional software engineering.
📋 Practical Task
Integrating Newtonsoft.Json to Parse a Local JSON Configuration
In this exercise, you will move beyond the GUI and use the CLI to manage a dependency for a specific task.
- Create a new Console Application via the terminal using
dotnet new console -n JsonParserProject. - Instead of using the Visual Studio NuGet Manager, use the terminal to install the
Newtonsoft.Jsonpackage using thedotnet add packagecommand. - Create a string variable containing a raw JSON object representing a user (e.g.,
"{"Name": "Alice", "Age": 30, "Role": "Engineer"}"). - Create a C# class
Userwith matching properties. - Use
JsonConvert.DeserializeObject<User>()to turn that string into a typed C# object and print the user's Name to the console. - Open your
.csprojfile and verify that thePackageReferencefor Newtonsoft.Json is present and correctly versioned.
There are no comments for now.