C#
5
Вклад в тег
public class Interval
{
DateTime LeftBound { get; set; }
DateTime RightBound { get; set; }
public Interval(DateTime left, DateTime right)
{
LeftBound = left;
RightBound = right;
}
}
...
List<Interval> intervals = new List<Interval>
{
new Interval(DateTime.Parse("12:00:00"), DateTime.Parse("13:00:00")),
new Interval(DateTime.Parse("14:00:00"), DateTime.Parse("20:00:00"))
};
...
public Color CheckInterval(DateTime now, List<Interval> timeTable)
{
Color color = Color.Green;
foreach (Interval interval in timeTable)
{
if (now > interval.LeftBound && now < interval.RightBound)
{
color = Color.Red;
break;
}
}
return color;
}
...
label1.ForeColor = CheckInterval(DateTime.Now, intervals);
\0\u0001\0\0\0ÿÿÿÿ\u0001\0\0\0\0\0\0\0\f\u0002\0\0\0<Test1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null\u0005\u0001\0\0\0\fTest1.Artist\u0003\0\0\0\u001a<FirstName>k__BackingField\u0019<LastName>k__BackingField\u001a<SongTitle>k__BackingField\u0001\u0001\u0001\u0002\0\0\0\u0006\u0003\0\0\0\aMichael\u0006\u0004\0\0\0\aJackson\u0006\u0005\0\0\0\rGive In To Me\v"
[Serializable]
public class Artist
{
private string _firstName;
private string _lastName;
private string _songTitle;
public string FirstName { get => _firstName; set => _firstName = value; }
public string LastName { get => _lastName; set => _lastName = value; }
public string SongTitle { get => _songTitle; set => _songTitle = value; }
}
размер станет меньше (190 байт) и строка поменяется соответственно:\0\u0001\0\0\0ÿÿÿÿ\u0001\0\0\0\0\0\0\0\f\u0002\0\0\0<Test1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null\u0005\u0001\0\0\0\fTest1.Artist\u0003\0\0\0\n_firstName\t_lastName\n_songTitle\u0001\u0001\u0001\u0002\0\0\0\u0006\u0003\0\0\0\aMichael\u0006\u0004\0\0\0\aJackson\u0006\u0005\0\0\0\rGive In To Me\v
\aMichael\aJackson\rGive In To Me
private static string BytesToString(byte[] bytes)
{
char[] chars = Encoding.UTF7.GetString(bytes).ToCharArray();
StringBuilder result = new StringBuilder();
foreach (char c in chars) { result.Append(c); }
return result.ToString();
}