Select C#extension method collection
For the popular discussion post on Codeplex, "What are your favorite C#expansion methods?" We have compiled a series of excellent expansion methods, which can significantly enhance the function of the C#language.
One of the striking methods is
expansion methods, define as follows:
In
<code class="language-csharp">public static bool In<T>(this T source, params T[] list) { if(source == null) throw new ArgumentNullException("source"); return list.Contains(source); }</code>
Methods simplify the readability and maintenance of the code by eliminating the lengthy conditional sentences (for comparative values). It is especially useful to check multiple values for predefined collection.
The above is the detailed content of What Are Some Useful C# Extension Methods and How Do They Improve Code?. For more information, please follow other related articles on the PHP Chinese website!