C# extension method just got easier

We used to write code like this for setting up our extension. 

public static class MyExtensions { public static int WordCount(this string str) => str.Split([' ', '.', '?'], StringSplitOptions.RemoveEmptyEntries).Length; }

The new way of writing extension code is here


public static class MyExtensions { extension(string str) { public int WordCount() => str.Split([' ', '.', '?'], StringSplitOptions.RemoveEmptyEntries).Length; } }

Magic! 

Comments

Popular posts from this blog

vllm : Failed to infer device type

android studio kotlin source is null error

gemini cli getting file not defined error