C# › Extension Methods

How do you chain multiple extension methods together in a fluent style, and what design principle makes this possible?

Intermediate

Answer

As long as each extension method RETURNS a value of a type that has further applicable extension (or instance) methods, calls can be chained one after another — this is exactly the mechanism that makes LINQ's fluent query syntax (.Where().Select().OrderBy()) work.
public static class StringExtensions {
  public static string Trimmed(this string s) => s.Trim();
  public static string Capitalized(this string s) => char.ToUpper(s[0]) + s[1..];
}

string result = "  hello world  ".Trimmed().Capitalized(); // "Hello world"
Real-world example Building a fluent, chainable string-processing or validation API similar in style to LINQ's own method chaining.

Common follow-ups: How does LINQ itself use exactly this technique to implement its fluent Where/Select/OrderBy chain syntax?