V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
ShikiSuen
V2EX  ›  问与答

C# 有没有像 Swift 那样的转义封包(escaping closures)?

  •  
  •   ShikiSuen · 2022-06-18 07:38:41 +08:00 · 480 次点击
    这是一个创建于 650 天前的主题,其中的信息可能已经有所发展或是发生改变。
    ShikiSuen
        1
    ShikiSuen  
    OP
       2022-06-18 18:55:50 +08:00
    搞出來了。

    ```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()
    ```


    ```csharp
    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();
    }
    }
    ```
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5378 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 08:57 · PVG 16:57 · LAX 01:57 · JFK 04:57
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.