How to set default input value in .Net Console App?

前端 未结 8 1403
时光取名叫无心
时光取名叫无心 2020-12-11 16:01

How can you set a default input value in a .net console app?

Here is some make-believe code:

Console.Write("Enter weekly cost: ");
string inp         


        
8条回答
  •  一向
    一向 (楼主)
    2020-12-11 16:44

    You can use helper method like this:

    public static string ReadWithDefaults(string defaultValue)
    {
        string str = Console.ReadLine();
        return String.IsNullOrEmpty(str) ? defaultValue : str;
    }
    

提交回复
热议问题