本文整理汇总了C#中Tuple.GroupBy方法的典型用法代码示例。如果您正苦于以下问题:C# Tuple.GroupBy方法的具体用法?C# Tuple.GroupBy怎么用?C# Tuple.GroupBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tuple
的用法示例。
在下文中一共展示了Tuple.GroupBy方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VerifySchedule
private void VerifySchedule(Tuple<DayOfWeek, TimeSpan>[] scheduleData, DateTime now)
{
WeeklySchedule schedule = new WeeklySchedule();
foreach (var occurrence in scheduleData)
{
schedule.Add(occurrence.Item1, occurrence.Item2);
}
var expectedSchedule = scheduleData.GroupBy(p => p.Item1);
// loop through the full schedule a few times, ensuring we cross over
// a month boundary ensuring day handling is correct
for (int i = 0; i < 10; i++)
{
// run through the entire schedule once, ordering the expected times per day
foreach (var expectedScheduleDay in expectedSchedule)
{
foreach (TimeSpan time in expectedScheduleDay.OrderBy(p => p.Item2).Select(p => p.Item2))
{
DateTime nextOccurrence = schedule.GetNextOccurrence(now);
Assert.Equal(expectedScheduleDay.Key, nextOccurrence.DayOfWeek);
Assert.Equal(time, nextOccurrence.TimeOfDay);
now = nextOccurrence + TimeSpan.FromSeconds(1);
}
}
}
}
示例2: WriteTypedSubItemTable
// subItems: tuple<XML, inheritsFrom>[]
protected void WriteTypedSubItemTable(Tuple<XElement, string>[] subItems, string tableName, TextWriter writer, DocItemWriterContext context)
{
var describedSubItems = subItems
.GroupBy(x => x.Item1.Attribute("name").Value)
.ToDictionary(
g => g.Key,
g => g.Select(x =>
Tuple.Create(
x.Item1.Element("document").Element("member"),
x.Item1.Element("type").Value,
x.Item2
)
).ToArray()
);
WriteTypedSubItemTable(describedSubItems, tableName, writer, context, true);
}
示例3: IOLinks_PostAdjust
private static Tuple<int, int>[] IOLinks_PostAdjust(Tuple<int, int>[] initial, Set2D[] brainSets, Item2D[] io)
{
// Get the links and distances between brain sets
Tuple<int, double>[][] brainLinks = IOLinks_PostAdjust_BrainBrainLinks(brainSets);
// Turn the initial links into something more usable (list of links by brain)
BrainBurden[] ioLinks = initial.
GroupBy(o => o.Item1).
Select(o => new BrainBurden(o.Key, o.Select(p => p.Item2))).
ToArray();
// Make sure there is an element in ioLinks for each brainset (the groupby logic above only grabs brainsets that have links)
int[] missing = Enumerable.Range(0, brainLinks.Length).Where(o => !ioLinks.Any(p => p.Index == o)).ToArray();
ioLinks = UtilityCore.Iterate(ioLinks, missing.Select(o => new BrainBurden(o, Enumerable.Empty<int>()))).ToArray();
// Move one link at a time
while (true)
{
// Figure out how burdened each brain set is
foreach (BrainBurden brain in ioLinks)
{
brain.Recalc(brainSets, io);
}
// Find the best link to move
if (!IOLinks_PostAdjust_MoveNext(ioLinks, brainLinks, brainSets, io))
{
break;
}
}
// Just build it manually
//return ioLinks.Select(o => new { BrainIndex = o.Index, UtilityCore.Iterate(o.LinksOrig, o.LinksMoved)
//var test = ioLinks.
// Select(o => new { BrainIndex = o.Index, Links = UtilityCore.Iterate(o.LinksOrig, o.LinksMoved).ToArray() }).
// ToArray();
List<Tuple<int, int>> retVal = new List<Tuple<int, int>>();
foreach (BrainBurden brain in ioLinks)
{
foreach (int ioIndex in UtilityCore.Iterate(brain.LinksOrig, brain.LinksMoved))
{
retVal.Add(Tuple.Create(brain.Index, ioIndex));
}
}
return retVal.ToArray();
//return initial;
}