I have two classes as shown below (NumberDisplay and ClockDisplay) and program.cs.

class NumberDisplay

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _ssv111
{
    class NumberDisplay
    {
        // fields
        private int _hours;
        private int _minutes;
        // constructor
        public NumberDisplay()
        {
            _hours = 0;
            _minutes = 0;
        }

        // methods
       
        public void DisplayTime()
        {
            
                Console.WriteLine("Time set to {0}:{1}",
                    _hours < 10 ? "0" + _hours.ToString() : _hours.ToString(),
                    _minutes < 10 ? "0" + _minutes.ToString() : _minutes.ToString());


         }

        public void showTime()
        {
            Console.WriteLine("{0}:{1}",
                _hours < 10 ? "0" + _hours.ToString() : _hours.ToString(),
                _minutes < 10 ? "0" + _minutes.ToString() : _minutes.ToString());
        }

        public void SetTime(int hours, int minutes)
        {
            _hours = hours;
            _minutes = minutes;
            
        }
        
        
        public void TimeTick()
        {
            
            ++_minutes;
            if (_minutes == 60)
            {
                _minutes = 0;
                ++_hours;
                if (_hours == 24)
                {
                    _hours = 0;
                }
                
            }
            
                
        }
        
    }
   
}

program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Timers;

namespace _ssv111
{
    class Program
    {
        static void Main(string[] args)
        {
            int counter = 0;
            NumberDisplay nd = null;
            nd = new NumberDisplay();
            nd.SetTime(23, 35);
            


            nd.DisplayTime();
            nd.showTime();
            Console.WriteLine("");
            Console.WriteLine("The clock will go on for 10 minutes.");
            Console.WriteLine("");
            do
            {
                System.Threading.Thread.Sleep(60000);
                ++counter;
                nd.TimeTick();
                nd.showTime();
            } while (counter < 10);
            Console.Read();

        }

    }
}

class clockdisplay

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _ssv111
{
    class ClockDisplay 
    {
       
    }
}

My main question is how to move some code from numberdisplay to clockdisplay and make them interact.

This article has been dead for over six months. Start a new discussion instead.