private int _time_value = 0;
private string _time_name = "Unknown";
public TimeInDay(int time_value, string time_name)
{ _time_value = time_value; _time_name = time_name;}
public string Name {get {return _time_name;} }
return (_time_value & 0x00FF0000) >> 16;
if(value < 0 || (value > 23)) value = 0;
_time_value = (_time_value & 0x7F00FFFF) | ((value << 16) & 0x00FF0000);
return (_time_value & 0x0000FF00) >> 8;
if(value < 0 || value > 59) value = 0;
_time_value = (_time_value & 0x7FFF00FF) | ((value << 8) & 0x0000FF00);
return _time_value & 0x000000FF;
if(value < 0 || value > 59) value = 0;
_time_value = (_time_value & 0x7FFFFF00) | (value & 0x000000FF);
static public bool SwapHours<T>(ref T a, ref T b) {
if(a.GetType() == typeof(TimeInDay) && b.GetType() == typeof(TimeInDay))
int hours_temp = (a as TimeInDay).Hours;
(a as TimeInDay).Hours = (b as TimeInDay).Hours;
(b as TimeInDay).Hours = hours_temp;
T temp = a; a = b; b = temp;
static public bool SwapMinutes<T>(ref T a, ref T b) {
if(a.GetType() == typeof(TimeInDay) && b.GetType() == typeof(TimeInDay))
int minutes_temp = (a as TimeInDay).Minutes;
(a as TimeInDay).Minutes = (b as TimeInDay).Minutes;
(b as TimeInDay).Minutes = minutes_temp;
T temp = a; a = b; b = temp;
static public bool SwapSeconds<T>(ref T a, ref T b) {
if(a.GetType() == typeof(TimeInDay) && b.GetType() == typeof(TimeInDay))
int seconds_temp = (a as TimeInDay).Seconds;
(a as TimeInDay).Seconds = (b as TimeInDay).Seconds;
(b as TimeInDay).Seconds = seconds_temp;
T temp = a; a = b; b = temp;
public static void Main(string[] args)
TimeInDay td_1 = new TimeInDay(0x58212, "td_1");
TimeInDay td_2 = new TimeInDay(0x12582, "td_2");
Console.WriteLine("{0}: Hours: {1}, Minutes {2}, Seconds {3}",
td_1.Name, td_1.Hours, td_1.Minutes, td_1.Seconds);
Console.WriteLine("{0}: Hours: {1}, Minutes {2}, Seconds {3}",
td_2.Name, td_2.Hours, td_2.Minutes, td_2.Seconds);
SwapHours<TimeInDay>(ref td_1, ref td_2);
SwapMinutes<TimeInDay>(ref td_1, ref td_2);
SwapSeconds<TimeInDay>(ref td_1, ref td_2);
Console.WriteLine("{0}: Hours: {1}, Minutes {2}, Seconds {3}",
td_1.Name, td_1.Hours, td_1.Minutes, td_1.Seconds);
Console.WriteLine("{0}: Hours: {1}, Minutes {2}, Seconds {3}",
td_2.Name, td_2.Hours, td_2.Minutes, td_2.Seconds);