Converting years to days, hours, minutes C#

时间:2016-10-20 19:11:28

标签: c#

I am having difficulty converting my captured string to a double datatypes I think I am somewhat on the right track but some guidance would be appreciated. Thanks!

        //Capture the users name
        Console.WriteLine("Hello, Please enter you name: ");
        string userName = Console.ReadLine();

        //Capture the year in decimal datatype
        Console.WriteLine("Thanks" +userName+ "Now Please enter you age:");
        string userAge = Console.ReadLine();

        double userYear = double.Parse(userAge);

        double userDays = 365 * userYear;

        double userHours = 24 * userDays;

        double userSeconds = 86400 * userHours;

2 个答案:

答案 0 :(得分:0)

在LINQPad中,这对我来说非常合适:

enter image description here

答案 1 :(得分:-4)

Use the Double class, not the primary datatype double.

double number = double.Parse("1"); //don´t works, because double is a primary data type

double number = Double.Parse("1"); //works