TS
C#

TypeScript to C#

10 lessons

Progress0%
1Introduction: Two Languages, One Mind2Type Systems: Structural vs Nominal3Classes: Advanced Features4Generics and LINQ5Nullable Reference Types6Async/Await7Decorators to Attributes8Ecosystem9File I/O10Records and Pattern Matching
All Mirror Courses
TS
C#
Ecosystem
MirrorLesson 8 of 10
Lesson 8

Ecosystem

Ecosystem & Tooling

Introduction

In this lesson, you'll learn about ecosystem in C#. Coming from TypeScript, you already have a foundation for understanding this concept. We'll build on that knowledge while highlighting the key differences.

Mirror Card
TS
From TypeScript:

In TypeScript, you're familiar with ecosystem & tooling.

C#
In C#:

C# has its own approach to ecosystem & tooling, which we'll explore step by step.

The C# Way

Let's see how C# handles this concept. Here's a typical example:

C#
C# Example
// NuGet / .csproj
// dotnet add package Newtonsoft.Json

using System.Text.Json;

// Built-in HttpClient
var client = new HttpClient();
var json = await client.GetStringAsync("/api/user");
var user = JsonSerializer.Deserialize<User>(json);

// Built-in validation via DataAnnotations
// No zod needed — use FluentValidation for complex rules

// Testing: xUnit + FluentAssertions
[Fact]
public void AddReturnsSum() {
    Add(1, 2).Should().Be(3);
}

Comparing to TypeScript

Here's how you might have written similar code in TypeScript:

TS
TypeScript (What you know)
// npm / package.json
// npm install axios zod jest

import axios from "axios";
import { z } from "zod";

const UserSchema = z.object({
  id: z.number(),
  name: z.string(),
});

const user = UserSchema.parse(await axios.get("/api/user"));
Mirror Card
TS
From TypeScript:

You may be used to different syntax or behavior.

C#
In C#:

npm → NuGet (package manager), packages listed in .csproj

Mirror Card
TS
From TypeScript:

You may be used to different syntax or behavior.

C#
In C#:

.NET SDK includes many batteries: HttpClient, JSON, logging, DI

Mirror Card
TS
From TypeScript:

You may be used to different syntax or behavior.

C#
In C#:

No external schema validation library needed — DataAnnotations is built-in

Mirror Card
TS
From TypeScript:

You may be used to different syntax or behavior.

C#
In C#:

TypeScript runs on Node.js; C# runs on .NET (cross-platform, Windows/Linux/macOS)

Step-by-Step Breakdown

1. NuGet = npm

NuGet is the .NET package manager. Use dotnet add package <name> or edit .csproj. Packages are hosted on nuget.org (equivalent of npmjs.com).

TS
TypeScript
npm install axios
C#
C#
dotnet add package RestSharp
// or edit .csproj:
<PackageReference Include="RestSharp" Version="110.2.0" />

2. .NET Batteries Included

.NET includes HttpClient, System.Text.Json, dependency injection, and logging in the standard library. You need fewer third-party packages than in Node.js.

TS
TypeScript
import axios from "axios"; // third-party
import express from "express"; // third-party
C#
C#
// Built-in:
using System.Net.Http; // HttpClient
using System.Text.Json; // JSON
// ASP.NET Core is part of .NET SDK

3. dotnet CLI = npx/tsc/node

The dotnet CLI handles building, running, testing, and publishing. It replaces tsc, node, npm scripts, and jest in one tool.

TS
TypeScript
tsc && node dist/index.js
npm test
npm run build
C#
C#
dotnet run        # build + run
dotnet test       # run tests
dotnet publish    # production build

4. .NET Use Cases

.NET is dominant in enterprise Windows environments, ASP.NET APIs, game development (Unity uses C#), cloud services on Azure, and cross-platform desktop apps (MAUI).

TS
TypeScript
// TypeScript: web front-end, Node APIs, serverless, CLIs
C#
C#
// C# .NET: enterprise APIs, cloud (Azure),
// Unity games, Windows desktop (WPF/MAUI),
// cross-platform microservices
Rule of Thumb
Choose C# when you need .NET ecosystem integration, enterprise tooling, or Unity development.

Common Mistakes

When coming from TypeScript, developers often make these mistakes:

  • npm → NuGet (package manager), packages listed in .csproj
  • .NET SDK includes many batteries: HttpClient, JSON, logging, DI
  • No external schema validation library needed — DataAnnotations is built-in
Common Pitfall
Don't assume C# works exactly like TypeScript. While the concepts may be similar, the syntax and behavior can differ significantly.

Key Takeaways

  • NuGet (nuget.org) is the .NET equivalent of npm — use dotnet add package
  • .NET SDK includes HttpClient, JSON, DI, and logging — fewer third-party deps needed
  • dotnet CLI replaces tsc, node, npm scripts, and jest in one tool
  • C# dominates enterprise, Azure cloud, Unity games, and Windows desktop development
Rule of Thumb
The best way to learn is by doing. Try rewriting some of your TypeScript code in C# to practice these concepts.
PreviousNext