Możesz skorzystać ze struktury TimeSpan
i jej metody TimeSpan.Parse(string)
.
Albo możesz sobie zrobić swoją:
public struct Time : IComparable<Time>, IEquatable<Time>
{
private readonly int _hour;
private readonly int _minute;
private readonly int _second;
public Time(int hour, int minute, int second)
{
_hour = hour;
_minute = minute;
_second = second;
}
public Time(int hour, int minute) : this(hour, minute, 0)
{
}
public static Time Parse(string input)
{
// TODO
// parse from "XX:XX" and "XX:XX:XX"
throw new NotImplementedException();
}
public static bool operator <(Time first, Time second)
{
// TODO
throw new NotImplementedException();
}
public static bool operator <=(Time first, Time second)
{
// TODO
throw new NotImplementedException();
}
public static bool operator >(Time first, Time second)
{
// TODO
throw new NotImplementedException();
}
public static bool operator >=(Time first, Time second)
{
// TODO
throw new NotImplementedException();
}
public static bool operator ==(Time first, Time second)
{
// TODO
throw new NotImplementedException();
}
public static bool operator !=(Time first, Time second)
{
// TODO
throw new NotImplementedException();
}
public int CompareTo([AllowNull] Time other)
{
// TODO
throw new NotImplementedException();
}
public bool Equals([AllowNull] Time other)
{
// TODO
throw new NotImplementedException();
}
public override bool Equals(object obj)
{
// TODO
throw new NotImplementedException();
}
public override int GetHashCode()
{
// TODO
throw new NotImplementedException();
}
}