Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我只是想知道这是否可能:
int custom = Console.ReadLine(); //or string custom? Console.WriteLine(DateTime.Now.Add(custom);
我知道这Console.ReadLine()等于string。但尽管如此,我确信这在某种程度上是可能的。谷歌帮不了我,所以我想我会是第一个问的。(或者我只是不擅长搜索)
Console.ReadLine()
string
ReadLine()您可以将结果解析为int:
ReadLine()
int
int custom = 0; if(int.TryParse(Console.ReadLine(), out custom)) { Console.WriteLine(DateTime.Now.AddHours(custom)); } else { Console.WriteLine("Invalid number!"); }