-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
47 lines (40 loc) · 1.48 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System;
using System.Collections.Generic;
namespace ConvertAll
{
class Program
{
// Function for converting one item into an Interval object
public static Interval TimeWindowToInterval(TimeWindow timeWindow)
{
return new Interval(){Start = timeWindow.From, End = timeWindow.To};
}
// Fordefined Property
static Interval[] openingIntervals {get;set;}
// Selfdefined List to convert
static List<TimeWindow> timeWindows = new List<TimeWindow>();
static void Main(string[] args)
{
// Add Time Windows
timeWindows.Add(new TimeWindow(){From = DateTime.Now ,To = (DateTime)DateTime.Now.AddHours(2)});
timeWindows.Add(new TimeWindow(){From = (DateTime)DateTime.Now.AddHours(2),To = (DateTime)DateTime.Now.AddHours(4)});
// Convert All
openingIntervals = timeWindows.ConvertAll(new Converter<TimeWindow, Interval>(TimeWindowToInterval)).ToArray();
// Check Output
foreach(var item in openingIntervals)
Console.WriteLine("Opening: "+item.Start + ", Closing: " + item.End);
}
}
// Fordefined Class
class Interval
{
public DateTime Start {get;set;}
public DateTime End {get;set;}
}
// Selfdefinded Class
class TimeWindow
{
public DateTime From {get;set;}
public DateTime To {get;set;}
}
}