我正在运行下面的代码而没有任何调试问题,但我的结果已关闭。
这是我的代码,用于反转字符串
{ namespace Code2040
{
public class ReverseString
{
public ReverseString ()
{
Task.Run (async () =>
//helper function is the post function for the webrequest
var helper = new Helper ();
Session.Instance.SetToken (JsonConvert.DeserializeObject<Response> (
await helper.Post ("http://challenge.code2040.org/api/getstring",
JsonConvert.SerializeObject (new { token = "Y6C15DVN99"
}))).Result);
Console.ReadKey (true);
//Reads out the line to verify if the token was printed out
Console.WriteLine (alorgorithmForReversingString.reverser (Session.Instance.Token));
//Console.WrtieLine (alorgorithmForReversingString.reverser (Session.Instance.Token));
Console.ReadLine ();
Console.WriteLine ("hello");
});
}
}
//Algorithim for reversing the string
static class alorgorithmForReversingString
{
public static string reverser (string tokenResult)
{
Console.WriteLine ("Debug");
char[] arr = tokenResult.ToCharArray ();
Array.Reverse (arr);
return new string (arr);
}
}
}
为了对此代码求和,我从Web帖子中获取了一个标记值,我将其变为一个字符串值,该字符串值可以反转字符串。但是,当我编译代码时,它甚至不会返回调试控制台写行变量。任何人都可以提供帮助。
答案 0 :(得分:0)
我的问题的解决方案是我在TaskAsync方法中有Console.WriteLine()。我相信TaskAsync方法只运行webpost并返回结果。
public class ReverseString
{
public ReverseString ()
{
Task.Run (async () => {
//helper function is the post function for the webrequest
var helper = new Helper ();
Session.Instance.SetToken (JsonConvert.DeserializeObject<Response> (
await helper.Post ("http://challenge.code2040.org/api/getstring",
JsonConvert.SerializeObject (new { token = "Y6C15DVN99"
}))).Result);
});
Console.WriteLine (alorgorithmForReversingString.reverser (Session.Instance.Token));
}
}
}