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();
        }
    }
}
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 :)

Yes, that was the problem ;)

Thank you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.