ソースコード using System; using System.Collections.Generic; using System.Linq; public static class IEnumerableExt { public static bool HasDuplication<TKey, TSource> ( this IEnumerable<TSource> self, Func<TSource, TKey> keySelector ) { return self .GroupBy( keySelector ) .Any( </tsource,></tsource></tkey,>…
ソースコード using System; public static class IntExt { public static int GetDigits( this int num ) { return num == 0 ? 1 : ( int ) Math.Log10( num ) + 1; } } 使用例 using System; public static class Program { private static void Main() { …
ソースコード using System; using System.Collections.Generic; using System.Linq; public static class IEnumerableExt { public static IEnumerable<TKey> GetDuplication<TKey, TSource> ( this IEnumerable<TSource> self, Func<TSource, TKey> keySelector ) { return self .GroupBy( keySelector )</tsource,></tsource></tkey,></tkey>…
ソースコード using System.Collections.Generic; using System.Linq; public static class IEnumerableExt { public static IEnumerable<(T item1, T item2)> Combine<T> ( this IEnumerable<T> first, IEnumerable<T> second ) { return first.SelectMany( i1 => se</t></t></t>…
はじめに 上記サイト様が、リストから組み合わせを取得できる関数を公開されております こちらを少し修正して、配列やリストから重複組合せを取得できる拡張メソッドを作りました ソースコード using System.Collections.Generic; using System.Linq; public…
はじめに 上記サイト様が、リストから組み合わせを取得できる関数を公開されております こちらを少し修正して、配列やリストから組合せを取得できる拡張メソッドを作りました ソースコード using System.Collections.Generic; using System.Linq; public sta…
ソースコード using System; using System.Reflection; public static class ParameterInfoExt { public static bool HasParams( this ParameterInfo param ) { var type = typeof( ParamArrayAttribute ); return param.GetCustomAttributes( type, false )…
ソースコード using System; public static class TypeExt { public static string GetAliasName( this Type self ) { switch ( self.FullName ) { case "System.Boolean": return "bool"; case "System.Byte": return "byte"; case "System.SByte": return …
ソースコード using System; using System.Collections.Generic; public static class ListExt { public static bool TryFind<T>( this List<T> self, Predicate<T> match, out T result ) where T : class { result = self.Find( match ); return result != null; } </t></t></t>…
はじめに 上記サイト様が公開されているプログラムを参考に 二次元配列を回転させる拡張メソッドを作成しました ソースコード public static class ArrayExt { // 時計回りに 90 度回転 public static T[,] RotateClockwise<T>( this T[,] self ) { int rows = </t>…
ソースコード using System.Text.RegularExpressions; public static class StringExt { public static int ExtractInteger( this string self ) { return int.Parse( Regex.Replace( self, @"[^0-9]", string.Empty ) ); } } 使い方 var str1 = "s012"; Con…
はじめに 「FastEnum」をプロジェクトに追加することで 高速な列挙型の API を使用できるようになります インストール Visual Studio メニューの「ツール>NuGet パッケージ マネージャー> ソリューションの NuGet パッケージの管理」を選択します 「参照」タ…
はじめに 「FastLinq」をプロジェクトに追加することで 高速な LINQ を使用できるようになります インストール Visual Studio メニューの「ツール>NuGet パッケージ マネージャー> ソリューションの NuGet パッケージの管理」を選択します 「参照」タブを選…
ソースコード using System.Collections.Generic; using System.Linq; public static class IListExt { public static void Deconstruct<T> ( this IList<T> self, out T first, out IList<T> rest ) { first = self.Count > 0 ? self[ 0 ] : default; rest = self.Sk</t></t></t>…
ソースコード using System; using System.Collections.Generic; public static class IEnumerableExt { public static IEnumerable<(int index, T value)> WithIndex<T> ( this IEnumerable<T> source ) { if ( source == null ) { throw new ArgumentNullExcepti</t></t>…
ソースコード using System.Collections.Generic; using System.Linq; public static class IEnumerableExt { public static IEnumerable<T> Concat<T> ( this IEnumerable<T> first, params T[] second ) { return Enumerable.Concat( first, second ); } } 使用例 </t></t></t>…
ソースコード using System; using System.Collections.Generic; public static class IEnumerableExt { public static Tuple<IEnumerable<T>, IEnumerable<T>> Partition<T> ( this IEnumerable<T> self, Func<T, bool> predicate ) { var ok = new List<T>(); var ng = new List<T>(); foreach ( v</t></t></t,></t></t></t></ienumerable<t>…
ソースコード using System.Collections.Generic; using System.Linq; public static class IEnumerableExt { public static IEnumerable<T> Flatten<T> ( this IEnumerable<IEnumerable<T>> self ) { return self.SelectMany( c => c ); } } 使用例 通常 foreach ( var n in list</ienumerable<t></t></t>…
ソースコード using System.Collections.Generic; public static class DictionaryExt { public static bool Remove<TKey, TValue> ( this Dictionary<TKey, TValue> self, TKey key, out TValue value ) { self.TryGetValue( key, out value ); return self.Remove( key ); } } 使用方法</tkey,></tkey,>…
ソースコード System.Random 版 using System; using System.Collections.Generic; using System.Linq; public static partial class IEnumerableExt { private static readonly Random m_random = new Random(); public static T RandomAt<T>( this IEnumerable<T></t></t>…
はじめに 「LinqFaster」をプロジェクトに追加することで 高速な LINQ を使用できるようになります インストール Visual Studio メニューの「ツール>NuGet パッケージ マネージャー> ソリューションの NuGet パッケージの管理」を選択します 「参照」タブを…
ソースコード public static class StringExt { public static bool IsLower( this string self ) { for ( int i = 0; i < self.Length; i++ ) { if ( char.IsUpper( self[ i ] ) ) { return false; } } return true; } } 使い方 var str = "abcde"; var isL…
ソースコード public static class StringExt { public static bool IsUpper( this string self ) { for ( int i = 0; i < self.Length; i++ ) { if ( char.IsLower( self[ i ] ) ) { return false; } } return true; } } 使い方 var str = "ABCDE"; var isU…
ソースコード using System; using System.Linq; public static class StringExt { public static string GetFirstLine( this string self ) { var separator = new [] { Environment.NewLine }; return self .Split( separator, StringSplitOptions.None ) …
ソースコード using System.Collections.Generic; using System.Text; public static class StringExt { /// <summary> /// 指定されたバイト数で文字列を分割して返します /// </summary> public static IList<string> SplitByMultiByte( this string self, int count ) { var result =</string>…
ソースコード using System; using System.Diagnostics; public static class StopwatchExt { /// <summary> /// yyyy/MM/dd HH:mm:ss 形式の文字列に変換して返します /// </summary> public static string ToPattern( this Stopwatch self ) { return new DateTime( self.Elap…
はじめに 「Enums.NET」をプロジェクトに追加することで パフォーマンスに優れた列挙型を使用できるようになります インストール Visual Studio メニューの「ツール>NuGet パッケージ マネージャー> ソリューションの NuGet パッケージの管理」を選択します …
はじめに 「Linq.Extras」をプロジェクトに追加することで LINQ で使用できる拡張メソッドが増えます インストール Visual Studio メニューの「ツール>NuGet パッケージ マネージャー> ソリューションの NuGet パッケージの管理」を選択します 「参照」タブ…
はじめに 「LinqToExcel」をプロジェクトに追加することで LINQ を使用して Excel からデータを抽出できるようになります インストール Visual Studio メニューの「ツール>NuGet パッケージ マネージャー> ソリューションの NuGet パッケージの管理」を選択…
はじめに 「SearchExtensions」をプロジェクトに追加することで LINQ で使用できる検索用の拡張メソッドが増えます インストール Visual Studio メニューの「ツール>NuGet パッケージ マネージャー> ソリューションの NuGet パッケージの管理」を選択します …