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<string> closure) {
string testString = "123";
closure(testString);
}
static void usage() {
Action<string> testStr = Console.WriteLine;
someFunctionWithNonescapingClosure(testStr);
}
static void Main(string[] args) { usage(); }
}