.net made easy[]

New .NET 11 APIs: LINQ FullJoin, Process Helpers and More

All levelsLesson 309 of 325·Production .NET·18 min read·Updated

Every .NET release quietly adds dozens of small helpers that remove boilerplate you've been writing by hand. These are the .NET 11 ones you're most likely to use, with a short example for each.

Big language features get the headlines, but day-to-day code improves through small library additions: a method that saves you ten lines here, a type that removes an awkward copy there. .NET 11 adds a long list of them, many aimed at advanced scenarios such as cryptography and hardware intrinsics.

You don't need all of them. This lesson picks the ones that matter for everyday programs, the kind you'd write after finishing this course, and shows each one with a small, complete example taken from Microsoft's own documentation.

In this lesson, you'll learn LINQ's new FullJoin and tuple-returning joins, the one-line Process helpers, EqualityComparer<T>.Create, generic random numbers, new in-memory streams, JSON Lines output, and two compression changes worth knowing.

What Is It?

The Simple Explanation

The base class libraries are the ready-made code that ships with .NET: collections, LINQ, files, JSON, networking and more. Each new version adds methods and types to them. In .NET 11 they're all available as soon as your project targets net11.0, with no extra NuGet packages.

The Technical Definition

.NET 11 extends System.Linq (FullJoin, plus tuple-returning LeftJoin, RightJoin, Join and GroupJoin overloads across Enumerable, Queryable and AsyncEnumerable), System.Diagnostics.Process (run-and-capture helpers, TryGetProcessById, signals and exit status), System.Collections.Generic (EqualityComparer<T>.Create), System.Random (NextInteger<T>, NextBinaryFloat<T>), System.IO (four new in-memory Stream types), System.Text.Json (union types and JSON Lines) and System.IO.Compression (Zstandard types, ZIP CRC32 checks).

Before .NET 11

  • Full outer joins needed a left join, a right join and a union
  • Running a command meant wiring up ProcessStartInfo and output events
  • A custom comparer meant writing a whole class
  • Passing a string to a Stream API meant encoding it to a byte array first

With .NET 11

  • a.FullJoin(b, x => x.Key, y => y.Key) returns matched pairs
  • await Process.RunAndCaptureTextAsync("git", ["status"])
  • EqualityComparer<T>.Create(p => p.Name)
  • new StringStream(text, Encoding.UTF8)

Why Does It Exist?

The Problem — The Same Boilerplate, Everywhere

Some tasks appear in almost every codebase: joining two lists where either side might be missing, running an external tool and reading its output, comparing objects by one property. Each team wrote its own helper, often with small bugs, such as forgetting to read the error output or deadlocking while waiting for a process.

The Solution — Ship the Helper Once, Correctly

When a pattern is common enough, the .NET team adds a well-tested version to the libraries. Your code gets shorter, and the tricky details (encoding, buffering, timeouts, edge cases) are handled by code that millions of apps share.

Big Picture

LINQ
FullJoin and joins that return tuples, with no result selector needed
Process
Run a command and capture its output in one call
Collections
EqualityComparer<T>.Create(keySelector)
I/O and JSON
In-memory streams, JSON Lines, Zstandard compression

How It Works

USING A NEW API
1. TARGET net11.0
<TargetFramework>net11.0</TargetFramework>
▼
2. NO EXTRA PACKAGES
  • These APIs are part of the shared framework. Most are in namespaces you already import by default, such as System.Linq and System.Collections.Generic.
▼
3. CALL THE METHOD
  • IntelliSense shows the new overloads as soon as the project targets .NET 11.
▼
4. MULTI-TARGETING? GUARD IT
  • A library that also targets net10.0 can't call .NET 11-only APIs in its .NET 10 build. Use #if NET11_0_OR_GREATER around them.

1. LINQ: FullJoin and Joins That Return Tuples

In lesson 115 you used Join, which keeps only the items that match on both sides. LINQ also has LeftJoin and RightJoin, which keep every item from one side, and .NET 11 adds **FullJoin, which keeps every item from both** sides. In .NET 11 you can also leave out the result selector: these joins can simply hand back a pair (a tuple) that you deconstruct with foreach (var (a, b) in ...).

var products = new List<(int Id, string Name, string? Category)> { (1, "Laptop", "Electronics"), (2, "Mouse", "Electronics"), (3, "Orphan", null), // no matching category }; var categories = new List<(string Name, string Description)> { ("Electronics", "Electronic devices"), ("Furniture", "Office furniture"), // no matching product }; var fullJoined = products.FullJoin(categories, p => p.Category, c => c.Name); foreach (var (product, category) in fullJoined) Console.WriteLine($"{product.Name ?? "(none)"}: {category.Description ?? "(none)"}"); // Laptop: Electronic devices // Mouse: Electronic devices // Orphan: (none) // (none): Office furniture

When one side has no match, its half of the pair is default, which is null for these fields, hence the ?? fallbacks. EF Core 11 translates FullJoin into SQL FULL JOIN, so the same idea works against a database (see lesson 355).

2. Run a Command and Capture Its Output

Running an external program used to mean creating a ProcessStartInfo, setting redirect flags, starting the process, reading both output streams carefully so it didn't freeze, then waiting for it to exit. .NET 11 adds one-shot helpers:

using System.Diagnostics; ProcessTextOutput result = await Process.RunAndCaptureTextAsync( "git", ["status", "--porcelain"]); Console.WriteLine(result.StandardOutput); Console.WriteLine($"Exit code: {result.ExitStatus.ExitCode}");

The family includes Process.Run/RunAsync (run and get the exit status) and RunAndCaptureText/RunAndCaptureTextAsync (also capture standard output and standard error). There's also Process.TryGetProcessById, which returns false instead of throwing when no process has that ID, plus StartAndForget for launching a program you don't intend to wait for.

3. A Comparer From One Lambda

In lesson 091 you saw that comparing objects "by one property" needs both Equals and GetHashCode. Writing a comparer class for that was tedious. EqualityComparer<T>.Create builds one from a key selector:

var byName = EqualityComparer<(string Name, int Age)>.Create(p => p.Name); var people = new HashSet<(string Name, int Age)>(byName) { ("Alice", 30), ("Bob", 25), ("Alice", 40), // same name: not added }; Console.WriteLine(people.Count); // 2

The comparer uses the selected key for both equality and hashing, so the two methods can never disagree, which was the classic bug when writing them by hand.

4. Random Numbers of Any Numeric Type

int i = Random.Shared.NextInteger<int>(); long l = Random.Shared.NextInteger<long>(0L, 100L); byte b = Random.Shared.NextInteger<byte>(maxValue: (byte)10); double d = Random.Shared.NextBinaryFloat<double>(); Half h = Random.Shared.NextBinaryFloat<Half>();

NextInteger<T> and NextBinaryFloat<T> work with any numeric type that implements the right generic math interfaces, so you no longer need casts like (byte)Random.Shared.Next(10).

5. Streams Over Data You Already Have

Many APIs accept a Stream. If your data was a string or a memory buffer, you used to copy it into a MemoryStream first. .NET 11 adds four Stream types that wrap existing data without copying: StringStream, ReadOnlyMemoryStream, WritableMemoryStream and ReadOnlySequenceStream.

using System.Text; // Hand a string to any API that wants a Stream, with no byte[] copy. using Stream config = new StringStream(yamlText, Encoding.UTF8); var settings = ParseConfiguration(config); // Expose an existing buffer as a read-only stream, e.g. as an HTTP body. ReadOnlyMemory<byte> payload = GetPayload(); using Stream body = new ReadOnlyMemoryStream(payload); await httpClient.PostAsync(uri, new StreamContent(body));

(yamlText, ParseConfiguration, GetPayload, httpClient and uri stand for your own variables and methods.)

6. JSON: Unions and JSON Lines

System.Text.Json, which you met in lesson 047, understands the C# 15 union types from lesson 348: it writes the active case directly, so a union holding "hello" becomes "hello" and one holding 42 becomes 42. It can also write JSON Lines (JSONL), one JSON value per line, a format log tools and data pipelines love because each line can be read on its own:

using System.IO.Pipelines; using System.Text.Json; static async IAsyncEnumerable<int> GenerateNumbers() { for (int i = 0; i < 5; i++) { yield return i; await Task.Yield(); } } using var jsonlStream = new MemoryStream(); PipeWriter jsonlPipe = PipeWriter.Create(jsonlStream); // topLevelValues: true writes one value per line: 0\n1\n2\n3\n4\n await JsonSerializer.SerializeAsyncEnumerable(jsonlPipe, GenerateNumbers(), topLevelValues: true); await jsonlPipe.CompleteAsync();

Without topLevelValues: true, the same call writes one JSON array: [0,1,2,3,4].

7. Two Compression Changes Worth Knowing

Simple Example

Here's a small program that combines two of the new APIs: it removes duplicate customers by email address, ignoring case, using a comparer built in one line.

var byEmail = EqualityComparer<Customer>.Create( c => c.Email, StringComparer.OrdinalIgnoreCase); // optional comparer for the key itself Customer[] imported = [ new("Ana", "ana@example.com"), new("Ben", "ben@example.com"), new("Ana B.", "ANA@example.com"), // same email, different case ]; var unique = imported.Distinct(byEmail).ToList(); Console.WriteLine(unique.Count); // 2 public record Customer(string Name, string Email);

Code → Meaning → Result: EqualityComparer<Customer>.Create takes the property to compare (the email) and, optionally, a comparer for that key (case-insensitive). Distinct then keeps the first customer for each email address, so the duplicate "Ana B." entry is removed.

Real-World Example

A small release script checks whether a Git repository has uncommitted changes before publishing. With .NET 11 it fits in a few lines, and it could even be a single-file app run with dotnet run release.cs:

using System.Diagnostics; ProcessTextOutput status = await Process.RunAndCaptureTextAsync("git", ["status", "--porcelain"]); if (status.ExitStatus.ExitCode != 0) { Console.WriteLine("git failed. Is this a Git repository?"); return; } if (!string.IsNullOrWhiteSpace(status.StandardOutput)) { Console.WriteLine("You have uncommitted changes. Commit them before releasing:"); Console.WriteLine(status.StandardOutput); return; } Console.WriteLine("Working tree is clean. Publishing...");

Analogy

New Tools in the Same Toolbox

Upgrading to .NET 11 is like opening your usual toolbox and finding a few new tools inside: a screwdriver with the right bit already fitted, a tape measure that also works as a level. You could manage without them, and your old tools still work, but the new ones make common jobs quicker and harder to get wrong.

Under the Hood

Common Confusion

1. "FullJoin is the same as a Union" — no, it pairs items up

Union combines two lists of the same type into one list. FullJoin pairs items from two different lists by a key, keeping unmatched items on either side with default as their partner.

2. "These APIs need NuGet packages" — no, they're in the box

Everything in this lesson ships with .NET 11 itself. Target net11.0 and they're available.

3. "My .NET 10 project can use them" — no, they need the .NET 11 libraries

New APIs exist only in the new framework. A project targeting net10.0 can't call FullJoin or Process.RunAndCaptureTextAsync, even when built with the .NET 11 SDK.

Common Mistakes

Mistake 1 — Forgetting that the missing side is default

The mistake: Writing category.Description.Length inside a FullJoin loop and getting a NullReferenceException for the unmatched rows.

The fix: In a full join, either side can be default. Use ?. and ?? as in the example, or filter out the unmatched rows first.

Mistake 2 — Ignoring the exit code

The mistake: Calling RunAndCaptureTextAsync and using StandardOutput without checking ExitStatus.ExitCode, so a failed command looks like an empty result.

The fix: Check the exit code first, as in the release-script example. A non-zero code usually means the command failed.

When Should I Use It?

Mental Model

LINQ: Join (both match), LeftJoin/RightJoin (one side kept), FullJoin (both sides kept).
Process: RunAndCaptureTextAsync(program, args) gives output plus exit status in one call.
Comparer from a lambda: EqualityComparer<T>.Create(x => x.Key).

Remember: .NET 11's library additions replace common hand-written helpers with tested, built-in ones.

Key Takeaway


Check Your Understanding

Three questions on choosing the right new API.

1. You need every customer from system A and every customer from system B, paired up where their IDs match. Which .NET 11 LINQ method fits best?

Show answer

Correct: C

Why C is correct: FullJoin keeps all items from both sequences, pairing them where keys match and using default for the missing side.

Why A is incorrect: Join keeps only the customers that exist in both systems.

Why B is incorrect: LeftJoin keeps everything from A but drops customers that exist only in B.

Why D is incorrect: Union merges two lists of the same type; it doesn't pair items by key.

Reinforcement: Both sides kept = FullJoin.

2. What does EqualityComparer<Person>.Create(p => p.Email) give you?

Show answer

Correct: A

Why A is correct: The factory builds an IEqualityComparer<Person> whose Equals and GetHashCode both use the selected key, so it works correctly in HashSet, Distinct and dictionaries.

Why B is incorrect: It doesn't produce data. It produces a comparer you pass to other APIs.

Why C is incorrect: Sorting uses IComparer<T> and OrderBy. This creates an equality comparer, not a sort order.

Why D is incorrect: Reference comparison is the default for classes. Create exists to compare by a key instead.

Reinforcement: One lambda in, a correct equality comparer out.

3. Your app reads uploaded ZIP files. What .NET 11 change should you plan for?

Show answer

Correct: B

Why B is correct: ZipArchive now checks each entry's CRC32 when reading, so damaged files that used to slip through now throw, and you should handle that.

Why A is incorrect: ZIP support is still there, and it gained features such as password-protected entries.

Why C is incorrect: Zstandard is a separate compression format. ZIP archives keep their own methods.

Why D is incorrect: Async ZIP APIs exist, including new OpenAsync overloads.

Reinforcement: Stricter ZIP checks: catch InvalidDataException for user uploads.

Those are the library highlights. The next lesson moves up a level to the frameworks built on top: what's new for web APIs in ASP.NET Core 11 and for databases in EF Core 11.