【问题标题】:How to send ref parameter to async method [closed]如何将 ref 参数发送到异步方法 [关闭]
【发布时间】:2022-08-18 22:27:51
【问题描述】:
    static async Task<bool>  GetContentLength(string fn, ref long charCount, ref long lineCount, ref TimeSpan elapsed)
    {
        try
        {
            var startTime = DateTime.Now;
            var lines = await File.ReadAllLinesAsync(fn);

            lineCount = lines.Count();
            charCount = lines.Sum(x => x.Count());
                
                
              //  (x => x.Count());
            elapsed = DateTime.Now - startTime;
            return true;
        }
        catch (Exception ex)
        {
            // logging ex
            return false;
        }
    }
  • 欢迎来到堆栈溢出!您的代码以何种方式无法按预期工作?请详细说明您正在观察的具体问题以及您进行了哪些调试。要了解有关此社区的更多信息以及我们如何为您提供帮助,请从 tour 开始并阅读 How to Ask 及其链接资源。
  • 只需返回一个元组。

标签: c# .net async-await


【解决方案1】:

你根本做不到。

而是将in 部分(初始值)作为参数发送,并使用返回来获取值。

【讨论】:

    猜你喜欢
    • 2021-01-28
    • 2021-07-03
    • 2019-12-26
    • 1970-01-01
    • 2016-11-22
    • 2023-03-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多