Skip to content

Instantly share code, notes, and snippets.

@ufcpp
Created May 10, 2021 02:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ufcpp/9bbce01cdbed7b4266e488cd55e8a8e6 to your computer and use it in GitHub Desktop.
Save ufcpp/9bbce01cdbed7b4266e488cd55e8a8e6 to your computer and use it in GitHub Desktop.
static っぽく見えるけどインスタンスメソッドが生成されることがあるやつ
using System;
class Program
{
static void Main()
{
Action a1 = M;
Console.WriteLine(a1.Method.IsStatic); // true
Action a2 = static () => { };
Console.WriteLine(a2.Method.IsStatic); // false。ラムダ式の仕様。インスタンスメソッドの方が速いからインスタンスメソッドで生成してしまう。
Action a3 = local;
Console.WriteLine(a3.Method.IsStatic); // true
static void local() { }
}
static void M() { }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment