Hello!

How can I make this code (converting seconds to hours, minutes and seconds) that the program will have a subroutine function?
Subroutine needs to return a full-time.

The code is:

class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Enter the number of seconds: ");
            int seconds = int.Parse(Console.ReadLine());

            TimeSpan fullTime = TimeSpan.FromSeconds(seconds);
            
            Console.Write("Full-time is: {0}", fullTime);
            Console.ReadKey();
        }
    }
}

Edited 5 Years Ago by trume: /

class Program {
    public static void Main() {
        Console.Write("Enter the number of seconds: ");
        int seconds = int.Parse(Console.ReadLine());

        TimeSpan fullTime = ConvertToHMS(seconds);
  
        Console.Write("Full-time is: {0}", fullTime);
        Console.ReadKey();
    }

    public TimeSpan ConvertToHMS(int n) {
        return TimeSpan.FromSeconds(n);
    }
}

Not very useful but it is a subroutine.

This code has an error:
An object reference is required for the non-static field, method, or property, Program.ConvertToHMS(int)

Sorry. Line 12 is missing the word 'static' at the beginning.

That's what I get for coding into the reply window :)

This question has already been answered. Start a new discussion instead.