概要 using System.Linq; using UnityEngine; public class Example : MonoBehaviour { private static string[] m_list = { "フシギダネ", "フシギソウ", "フシギバナ", }; private void Update() { // 匿名型 var r1 = m_list.Select( c => new { name = c…
概要 using UnityEngine; public interface ICharacter { } public struct Character : ICharacter { } public class Example : MonoBehaviour { private Character m_character = new Character(); private void Update() { Hoge1( m_character ); } privat…
概要 using System; using UnityEngine; public class Example : MonoBehaviour { private enum Type { GRASS, FIRE, WATER, } private void Update() { Hoge1( Type.FIRE ); } private void Hoge1( Enum value ) { } } System.Enum で引数を受け取ると GC A…
概要 using System.Linq; using UnityEngine; public class Example : MonoBehaviour { private static string [] m_list = { "フシギダネ", "フシギソウ", "フシギバナ", }; private void Update() { var name = "ピカチュウ"; // ここで return するので r…
概要 ラムダ式の => にカーソルを重ねるとキャプチャされている変数を確認できます 参考サイト様 https://www.slideshare.net/xin9le/dotnetperformancetips-170268354
概要 using System.Linq; using UnityEngine; public class Example : MonoBehaviour { private static string[] m_list = { "フシギダネ", "フシギソウ", "フシギバナ", }; private void Update() { var name = "ピカチュウ"; var result = m_list.Where( c…
概要 public sealed class Character { private readonly int m_id; private readonly string m_name; public Character() { Initialize( out m_id, out m_name ); } private void Initialize( out int id, out string name ) { id = 25; name = "ピカチュウ…
はじめに 上記サイト様が、リストから組み合わせを取得できる関数を公開されております こちらを少し修正して、配列やリストから重複組合せを取得できる拡張メソッドを作りました ソースコード 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>…
はじめに 「ByteSize」をプロジェクトに追加することで バイトサイズを簡単に扱うことができるようになります インストール Install-Package ByteSize パッケージマネージャーコンソールで上記のコマンドを入力します 使い方 コンストラクタ using ByteSizeL…
ソースコード 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…
概要 ハンドルされていない例外: System.Threading.ThreadStateException: OLE が呼び出される前に、現在のスレッドが Single Thread Apartment (STA) モードに設定されていなければなりません。 Main 関数に STAThreadAttribute が設定されていることを確認…
一覧 FastLinq - 高速な LINQ LinqFaster - 高速な LINQ LinqToExcel - Excel からデータを抽出できる ExtraLINQ - 使用できる拡張メソッドが増える Linq.Extras - 使用できる拡張メソッドが増える smooth.foundations - GC Alloc の発生が少ない LINQ Searc…
はじめに 「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>…
方法1 using System; using System.Collections.Generic; using System.Linq; public static class Program { private static void Main() { var table = new Dictionary<string, int> { { "フシギダネ", 1 }, { "フシギソウ", 2 }, { "フシギバナ", 3 }, }; // 最大値を</string,>…
ソースコード 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,>…
目次 目次 foreach で結合する LINQ で結合する(キーが重複する場合は例外) LINQ で結合する(キーが重複しても大丈夫) 参考サイト様 foreach で結合する using System; using System.Collections.Generic; public static class Program { private static…
ソースコード using System.Collections.Generic; using System.Collections.ObjectModel; public static class Program { private static void Main() { // 通常の Dictionary var table1 = new Dictionary<int, string> { { 1, "フシギダネ" }, { 2, "フシギソウ" }, { </int,>…
構造体を使用する方法 using System; using System.Collections.Generic; public static class Program { // 構造体でキー用のデータを定義 public struct KeyData { public int m_series; public int m_number; public KeyData( int series, int number ) {…
ソースコード using System; using System.Collections.Generic; using System.Linq; public static class Program { private static void Main() { var table = new Dictionary<int, string> { { 100, "フシギダネ" }, { 101, "フシギダネ" }, { 102, "フシギダネ" }, { </int,>…