C# Feature β Extension methods
Overview
Section titled βOverviewβExtension methods add static methods callable as if they were instance methods on the target type.
Introduced In
Section titled βIntroduced InβC# 3 (2007)
var text = ToTitleCase("hello world");var text = "hello world".ToTitleCase();Annotated Example
Section titled βAnnotated Exampleβpublic static class StringExtensions{ public static string ToTitleCase(this string s) => System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(s);}Gotchas & Best Practices
Section titled βGotchas & Best Practicesβ- Donβt overuse; avoid polluting IntelliSense. Prefer domain-relevant extensions.
Related Features
Section titled βRelated FeaturesβVersion Notes
Section titled βVersion Notesβ- Works across assemblies with
using.