-
C#樹林
Returning Multiple Values from Methods Using Tuples (ValueTuple) in C#
Using Tuples (ValueTuple), available since C# 7.0, allows you to easily return multiple values from a method. Previously, returning multiple values required using out arguments or defining specific classes or structures for the return va... -
C#樹林
【C#】タプル(ValueTuple)を使用してメソッドから複数の値を返す
C# 7.0 以降で利用可能な「タプル(ValueTuple)」を使用すると、メソッドから複数の値を簡単に返すことができます。 従来、複数の値を返すためには out 引数を使用するか、戻り値専用のクラスや構造体を定義する必要がありました。タプルを利用することで... -
C#樹林
[C#] Defining Immutable Objects Using Init-Only Setters
Introduced in C# 9.0, init accessors (init-only setters) allow you to easily define properties that can only be set during object initialization and become immutable (read-only) afterwards. Previously, creating immutable objects required... -
C#樹林
【C#】init専用セッターを使用して不変(Immutable)なオブジェクトを定義する
C# 9.0 で導入された init アクセサー(init-only setters)を使用すると、**オブジェクトの初期化時のみ値を設定可能で、その後は変更不可能(読み取り専用)**なプロパティを簡単に定義できます。 従来、不変なオブジェクトを作成するには「読み取り専用... -
C#樹林
[C#] Concisely Defining Property Get/Set Accessors Using Expression Bodies (=>)
Since C# 7.0, you can write both property get and set accessors as "expression-bodied members." This allows you to simply write property definitions using the arrow operator =>, replacing the traditional block { ... } and return state... -
C#樹林
【C#】プロパティのget/setアクセサーを式形式(=>)で簡潔に定義する
C# 7.0 から、プロパティの get アクセサーと set アクセサーの両方を「式形式のメンバー(Expression-bodied members)」として記述できるようになりました。 従来はブロック { ... } と return 文を用いて記述していたプロパティ定義を、アロー演算子 =&... -
C#樹林
[C#] Hiding Helper Methods within Scope Using Local Functions
Introduced in C# 7.0, Local Functions allow you to define a function directly inside another method. Previously, even small helper methods used only by a specific method had to be defined as private methods of the class. This often clutt... -
C#樹林
【C#】ローカル関数(Local Functions)でヘルパーメソッドをスコープ内に隠蔽する
C# 7.0 で導入された「ローカル関数」を使用すると、メソッドの内部に、そのメソッド専用の関数を定義することができます。 従来、特定のメソッドからしか呼ばれない小さなヘルパーメソッドであっても、クラスの private メソッドとして定義する必要があり... -
C#樹林
Simplifying Conditional Expressions with C# is Operator Pattern Matching (and/or/not)
By using the enhanced pattern matching introduced in C# 9.0, you can use the is operator to write value range checks, null checks, and logical operations (AND, OR) in a very intuitive and concise way. It allows you to reduce repetitive v... -
C#樹林
【C#】is演算子のパターンマッチング(and/or/not)で条件式を簡潔にする
C# 9.0 で強化されたパターンマッチングを利用すると、is 演算子を用いて、値の範囲チェックや null チェック、論理演算(かつ、または)を非常に直感的かつ簡潔に記述できるようになりました。 従来、&& や || を用いて繰り返していた変数記述を... -
C#樹林
[C#] Conditional Logic in Switch Case Labels (When Clause and Pattern Matching)
Since C# 7.0, the functionality of the switch statement has been significantly expanded to support Pattern Matching. This allows for not only simple constant matching but also type checking and detailed conditional logic using the when c... -
C#樹林
【C#】switch文のcaseラベルで条件判定を行う(when句とパターンマッチング)
C# 7.0 以降、switch 文の機能が大幅に拡張され、「パターンマッチング」が利用可能になりました。これにより、単なる定数の一致判定だけでなく、型の判定や、when 句を用いた詳細な条件判定が可能になっています。 従来は if-else 文を連ねて記述していた... -
C#樹林
[C#] Writing Concise Conditional Logic with Switch Expressions
Introduced in C# 8.0, Switch Expressions allow for more concise and intuitive coding compared to traditional switch statements. While traditional switch statements were "control structures (statements)," switch expressions are "expressio... -
C#樹林
【C#】switch式を使って条件分岐を簡潔に記述する
C# 8.0 で導入された「switch式(Switch Expressions)」を使用すると、従来の switch 文よりも簡潔で直感的な記述が可能になります。 従来の switch 文は「制御構造(ステートメント)」でしたが、switch式は「式(Expression)」であるため、結果を直接... -
C#樹林
[C#] Using Named Arguments to Improve Readability and Flexibility of Method Calls
Introduced in C# 4.0, Named Arguments allow you to explicitly specify the name of an argument when calling a method. Normally, method arguments must be passed in the order they are defined. However, by using named arguments, you can free... -
C#樹林
【C#】名前付き引数を利用してメソッド呼び出しの可読性と柔軟性を向上させる
C# 4.0 で導入された「名前付き引数(Named Arguments)」を使用すると、メソッドを呼び出す際に引数の名前を明示的に指定して値を渡すことができます。 通常、メソッドの引数は定義された順序通りに渡す必要がありますが、名前付き引数を使用することで、... -
C#樹林
[C#] Cleaning Up Code by Inlining Method Argument Definitions with Out Variable Declarations
Introduced in C# 7.0, Out variables allow you to declare a variable directly within the argument list when calling a method that has an out parameter. This eliminates the need to write a separate line to declare the variable beforehand, ... -
C#樹林
【C#】out変数宣言でメソッドの引数定義をインライン化し、コードをスッキリさせる
C# 7.0 で導入された「out 変数宣言(Out variables)」を使用すると、out 引数を持つメソッドを呼び出す際に、その引数部分で直接変数を宣言できるようになりました。 これにより、以前のように変数を事前に宣言するための行を記述する必要がなくなり、コ... -
C#樹林
[C#] Omitting Type Names in Instance Creation with Target-Typed New Expressions
Introduced in C# 9.0, Target-typed new expressions allow you to omit the type description when creating an instance and simply write new() provided the compiler can infer the type from the context. Previously, code tended to become verbo... -
C#樹林
【C#】ターゲット型new式を使ってインスタンス生成の型名を省略する
C# 9.0 で導入された「ターゲット型 new 式(Target-typed new expressions)」を使用すると、コンパイラが型を推論できる文脈において、インスタンス生成時の型記述を省略し、単に new() と記述することができます。 従来、型名が長いクラスやジェネリッ... -
C#樹林
[C#] Concisely Setting Default Values for Method Arguments Using the default Literal
Introduced in C# 7.1, the default literal allows you to omit the type name when specifying the default value of a type. This allows you to replace the verbose default(T) expression with a simple default when defining optional arguments f... -
C#樹林
【C#】defaultリテラルを使用してメソッド引数の既定値を簡潔に設定する
C# 7.1 で導入された default リテラルを使用すると、型の既定値(デフォルト値)を記述する際に型名を省略できるようになりました。 これにより、メソッドのオプション引数(省略可能な引数)を定義する際、default(T) と記述していた冗長な表現を defaul... -
C#樹林
[C#] Writing Safe Code by Eliminating Hardcoded Strings with the nameof Operator
The nameof operator, introduced in C# 6.0, is a feature that allows you to obtain the name of a type, member, or variable as a string at compile time. Previously, names were written as string literals (e.g., "variableName") when outputti... -
C#樹林
【C#】nameof演算子を使って文字列のハードコーディングを排除し、安全なコードを書く
C# 6.0 で導入された nameof 演算子は、型、メンバー、変数などの名前をコンパイル時に文字列として取得する機能です。 従来、ログ出力や例外のスロー時に対象の名前を文字列リテラル("variableName")として記述していましたが、これには「変数名を変更... -
C#樹林
[C#] Reducing Code Verbosity by Omitting Class Names with the using static Directive
The using static directive, introduced in C# 6.0, allows you to call static members (methods and properties) of a specified type directly without writing the type name every time. By applying this feature to frequently used static classe... -
C#樹林
【C#】using staticディレクティブでクラス名を省略し、コード記述量を減らす
C# 6.0 で導入された using static ディレクティブを使用すると、指定した型の静的メンバー(メソッドやプロパティ)を、型名を省略して直接呼び出すことができます。 頻繁に使用する静的クラス(System.Console や System.Math など)に対してこの機能を... -
C#樹林
[C#] Simplifying Code with Top-Level Statements (Omitting the Main Method)
Introduced in C# 9.0, Top-level statements allow you to omit the explicit entry point (Main method) that was traditionally required. This enables you to start programs simply, much like scripting languages, and significantly reduces boil... -
C#樹林
【C#】最上位レベルステートメントでMainメソッドを省略してコードを簡潔にする
C# 9.0 から導入された「最上位レベルステートメント(Top-level statements)」を使用すると、従来のエントリーポイント(Main メソッド)を明示的に記述する必要がなくなります。これにより、スクリプト言語のようにシンプルにプログラムを開始でき、特... -
お金樹林
docomoギガライトからahamoに変えるべきか。月7GB前後使う私の視点で比較_2025年12月10日
私は現在(2025年12月10日)、docomoのギガライトを使っています。データ使用量はだいたい月7GBくらいです。この使い方だと、ギガライトの料金が上限ステップにかかりやすく、ahamoの方が良いのではないかと気になりました。 この記事では、ギガライトとaham... -
Python樹林
[Python] Efficient String Replacement with Regex re.sub
When replacing strings in Python, the standard replace() method is sufficient for simple, fixed-text substitutions. However, when you need to perform flexible replacements based on patterns—such as "all whitespace characters" or "numbers...