小编sty*_*tyx的帖子

将 Async/Await JSON 反序列化结果移动到另一个函数

我有这个功能,最多可以获取 10 个项目作为输入列表

public async Task<KeyValuePair<string, bool>[]> PayCallSendSMS(List<SmsRequest> ListSms)
{
    List<Task<KeyValuePair<string, bool>>> tasks = new List<Task<KeyValuePair<string, bool>>>();

    foreach (SmsRequest sms in ListSms)
    {
        tasks.Add(Task.Run(() => SendSMS(sms)));
    }

    var result = await Task.WhenAll(tasks);
    return result;
}
Run Code Online (Sandbox Code Playgroud)

在这个函数中,我await要下载一些 JSON,然后反序列化它。

public async Task<KeyValuePair<string, bool>> SendSMS(SmsRequest sms)
 {
    //some code
      using (WebResponse response = webRequest.GetResponse())
    {
        using (Stream responseStream = response.GetResponseStream())
        {
            StreamReader rdr = new StreamReader(responseStream, Encoding.UTF8);
            string Json = await rdr.ReadToEndAsync();
            deserializedJsonDictionary = (Dictionary<string, object>)jsonSerializer.DeserializeObject(Json);
        }
    }
    //some code
     return …
Run Code Online (Sandbox Code Playgroud)

c# json task streamreader async-await

0
推荐指数
1
解决办法
48
查看次数

关于C中的一段代码的争论

我的朋友和我正在争论这段小代码:

#include <stdio.h>
#include <stdio.h>

int foo (int k) 
{
    int i, n;

    for (i = i ? 0 : i, n ^= n; i < sizeof(k) * 8;)
        n += k >> i++ & ~-2;
    return n;
}
Run Code Online (Sandbox Code Playgroud)

我怀疑它不会被编译,因为它i未初始化的,但我的朋友们认为它会.你怎么看?

c compiler-construction compiler-errors

-4
推荐指数
1
解决办法
98
查看次数