C# 写转义封包

Swift 原本的写法:

class test {
  static func someFunctionWithNonescapingClosure(closure: (String) -> Void) {
    let testString: String = "123"
    closure(testString)
  }

  static func usage() {
    someFunctionWithNonescapingClosure { newString in
      print(newString)

    }
  }
}

test.usage()

换 C# 之后:

using System;

class Untitled {
  static void someFunctionWithNonescapingClosure(Action closure) {
    string testString = "123";
    closure(testString);
  }

  static void usage() {
    Action testStr = Console.WriteLine;
    someFunctionWithNonescapingClosure(testStr);
  }
  static void Main(string[] args) { usage(); }
}

你可能感兴趣的:(C# 写转义封包)