本文整理汇总了C#中Tuple.ToList方法的典型用法代码示例。如果您正苦于以下问题:C# Tuple.ToList方法的具体用法?C# Tuple.ToList怎么用?C# Tuple.ToList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tuple
的用法示例。
在下文中一共展示了Tuple.ToList方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Skeleton
public Skeleton(Tuple<JointType, JointType>[] bones)
{
Bones = bones.ToList();
HashSet<JointType> joints = new HashSet<JointType>();
foreach (Tuple<JointType, JointType> bone in bones) {
joints.Add(bone.Item1);
joints.Add(bone.Item2);
}
Joints = joints.ToList();
}
示例2: GetReferencedAssemblies
/*
public static IAssemblySymbol[] GetReferencedAssemblies(IAssemblySymbol assembly)
{
var result = assembly.GetType().GetMethod("GetLinkedReferencedAssemblies", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(assembly, new object[0]);
if (result == null)
return new IAssemblySymbol[0];
return result.ToArray();
}
*/
public static IAssemblySymbol[] Sort(Tuple<IAssemblySymbol, IAssemblySymbol[]>[] assemblies)
{
var currentList = assemblies.ToList();
var prepend = new HashSet<Tuple<IAssemblySymbol, IAssemblySymbol[]>>();
do
{
prepend.Clear();
var indices = currentList.Select((x, i) => new { Item = x, Index = i }).ToDictionary(x => x.Item.Item1, x => x.Index);
for (var i = 0; i < currentList.Count; i++)
{
var item = currentList[i];
foreach (var referencedAssembly in item.Item2)
{
int assemblyIndex;
if (indices.TryGetValue(referencedAssembly, out assemblyIndex))
{
if (assemblyIndex > i)
{
var referencedAssemblyItem = currentList[assemblyIndex];
prepend.Add(referencedAssemblyItem);
}
}
}
}
if (prepend.Any())
{
var newItems = prepend.Concat(currentList.Where(x => !prepend.Contains(x))).ToArray();
currentList.Clear();
currentList.AddRange(newItems);
}
}
while (prepend.Any());
return currentList.Select(x => x.Item1).ToArray();
}
示例3: Save
public static void Save(string directory, Madingley.Common.Configuration c)
{
CreateDirectories(directory);
var convertTimeSteps = 12;
var parameters = new Tuple<string, string>[]
{
Tuple.Create("Parameter", "Value"),
Tuple.Create("Timestep Units", c.GlobalModelTimeStepUnit),
Tuple.Create("Length of simulation (years)", (c.NumTimeSteps / convertTimeSteps).ToString()),
Tuple.Create("Burn-in (years)", (c.BurninTimeSteps / convertTimeSteps).ToString()),
Tuple.Create("Impact duration (years)", (c.ImpactTimeSteps / convertTimeSteps).ToString()),
Tuple.Create("Recovery duration (years)", (c.RecoveryTimeSteps / convertTimeSteps).ToString()),
Tuple.Create("Plankton size threshold", c.PlanktonDispersalThreshold.ToString()),
Tuple.Create("Draw Randomly", c.DrawRandomly ? "yes" : "no"),
Tuple.Create("Extinction Threshold", c.ExtinctionThreshold.ToString()),
Tuple.Create("Maximum Number Of Cohorts", c.MaxNumberOfCohorts.ToString()),
Tuple.Create("Run Cells In Parallel", c.RunCellsInParallel ? "yes" : "no"),
Tuple.Create("Run Simulations In Parallel", c.RunSimulationsInParallel ? "yes" : "no"),
Tuple.Create("Run Single Realm", c.RunRealm),
Tuple.Create("Impact Cell Index", System.String.Join(";", c.ImpactCellIndices)),
// Tuple.Create("ImpactAll", if c.ImpactAll then "yes" else "no"),
Tuple.Create("Dispersal only", c.DispersalOnly ? "yes" : "no"),
Tuple.Create("Dispersal only type", c.DispersalOnlyType)
};
using (var writer = new StreamWriter(Path.Combine(directory, "SimulationControlParameters.csv")))
{
parameters.ToList().ForEach(kv => writer.WriteLine(String.Format("{0},{1}", kv.Item1, kv.Item2)));
}
var fileLocationParameters = new Tuple<string, string>[]
{
Tuple.Create("Parameter", "Value"),
Tuple.Create("Mass Bin Filename", "MassBinDefinitions.csv"),
Tuple.Create("Environmental Data File", "EnvironmentalDataLayers.csv"),
Tuple.Create("Cohort Functional Group Definitions File", "CohortFunctionalGroupDefinitions.csv"),
Tuple.Create("Stock Functional Group Definitions File", "StockFunctionalGroupDefinitions.csv"),
Tuple.Create("Ecological parameters file","EcologicalParameters.csv")
};
using (var writer = new StreamWriter(Path.Combine(directory, "FileLocationParameters.csv")))
{
fileLocationParameters.ToList().ForEach(kv => writer.WriteLine(String.Format("{0},{1}", kv.Item1, kv.Item2)));
}
EcologicalParameters.Save(c.EcologicalParameters, Path.Combine(directory, "Ecological Definition Files", "EcologicalParameters.csv"));
FunctionalGroupDefinitions.Save(c.CohortFunctionalGroupDefinitions, Path.Combine(directory, "Ecological Definition Files", "CohortFunctionalGroupDefinitions.csv"));
FunctionalGroupDefinitions.Save(c.StockFunctionalGroupDefinitions, Path.Combine(directory, "Ecological Definition Files", "StockFunctionalGroupDefinitions.csv"));
ScenarioParameters.SaveScenarios(c.ScenarioParameters, Path.Combine(directory, "Initial Model State Setup", "Scenarios.csv"));
}
示例4: findOrder
/*
Problem Statement
Two armies composed of magical creatures are facing off at a battlefield. To provide a more epic feel to the battle, the armies have agreed that each creature will attack exactly once and that only one creature may attack at a time.
Each creature has a might trait assigned to it. The order in which the creatures attack is uniquely determined by the following rules:
Creatures with higher might attack before creatures with lower might.
If creatures have equal might, attacking creatures alternate between armies. For example, if the last creature to attack was from the first army and the next creature could be from either army, a creature from the second army will attack next. If the very first attack is to be decided, a creature from the first army goes first.
If more than one creature in the same army has the same might, the creature given earlier in the input goes first.
You will be given the descriptions of the armies as two s, army1 and army2. Each element of army1 and army2 will be formatted as "NAME MIGHT" (quotes for clarity), where NAME is the name of a creature, and MIGHT is an integer, the might of that creature. Return a containing the creatures' names in the order in which they attack.
Definition
Class: Armies
Method: findOrder
Parameters: string[], string[]
Returns: string[]
Method signature: string[] findOrder(string[] army1, string[] army2)
(be sure your method is public)
Limits
Time limit (s): 840.000
Memory limit (MB): 64
Constraints
- army1 and army2 will each contain between 0 and 50 elements, inclusive.
- Each element of army1 and army2 will be formatted as "NAME MIGHT" (quotes for clarity).
- NAME in each element of army1 and army2 will be a string containing between 1 and 20 uppercase letters ('A'-'Z'), inclusive.
- MIGHT in each element of army1 and army2 will be an integer between 1 and 999, inclusive, without leading zeroes.
- No two creatures will have the same name.
Examples
0)
{ "DRAGON 10" }
{ "BOAR 1", "ELF 3" }
Returns: {"DRAGON", "ELF", "BOAR" }
The dragon is by far the mightiest and attacks first. The elf follows and the boar goes last.
1)
{ "SWORDSMAN 5", "ARCHER 3" }
{ "CENTAUR 2", "ELF 3" }
Returns: {"SWORDSMAN", "ELF", "ARCHER", "CENTAUR" }
The swordsman attacks first. The next creature could be either the archer or the elf because both have might 3. Since the first creature to attack was from the first army, the next will be the elf from the second army. The archer and centaur follow.
2)
{ "ARCHER 5", "PIXIE 3" }
{ "OGRE 10", "WOLF 10", "GOBLIN 3" }
Returns: {"OGRE", "WOLF", "ARCHER", "GOBLIN", "PIXIE" }
3)
{ "A 6", "B 7" }
{ }
Returns: {"B", "A" }
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
*/
public string[] findOrder(string[] army1, string[] army2)
{
Tuple<string, int>[] a1 = new Tuple<string, int>[army1.Length];
for (int i = 0; i < army1.Length; i++)
{
string[] a2 = army1[i].Split(' ');
a1[i] = new Tuple<string, int>(a2[0], int.Parse(a2[1]));
}
Tuple<string, int>[] b1 = new Tuple<string, int>[army2.Length];
for (int i = 0; i < army2.Length; i++)
{
string[] b2 = army2[i].Split(' ');
b1[i] = new Tuple<string, int>(b2[0], int.Parse(b2[1]));
}
List<Tuple<string, int>> a3 = a1.ToList();
List<Tuple<string, int>> a4 = new List<Tuple<string, int>>();
for (int i = 0; i < a3.Count - 1; i++)
{
if (a3[i].Item2 < a3[i + 1].Item2)
{
Tuple<string, int> temp = a3[i + 1];
a3[i + 1] = a3[i];
a3[i] = temp;
}
}
a1 = a3.ToArray();
List<Tuple<string, int>> b3 = b1.ToList();
List<Tuple<string, int>> b4 = new List<Tuple<string, int>>();
for (int i = 0; i < b3.Count - 1; i++)
{
if (b3[i].Item2 < b3[i + 1].Item2)
{
Tuple<string, int> temp = b3[i + 1];
b3[i + 1] = b3[i];
b3[i] = temp;
}
}
b1 = b3.ToArray();
string[] result = new string[b1.Length + a1.Length];
int lastAtk = 0;
int acounter = 0;
int bcounter = 0;
for (int i = 0; i < result.Length; i++)
{
if (a1.Length > i - acounter)
{
//.........这里部分代码省略.........
示例5: GetChains
private static List<Chain> GetChains(Tuple<int, int>[] segments)
{
// Find the points that have more than two segments pointing to them
var pointCounts = UtilityCore.Iterate(segments.Select(o => o.Item1), segments.Select(o => o.Item2)).
GroupBy(o => o).
Select(o => Tuple.Create(o.Key, o.Count())).
Where(o => o.Item2 > 2).
ToArray();
List<Tuple<int, int>> segmentList = segments.ToList();
if (pointCounts.Length == 0)
{
// There are no junctions, so just return the unique loops
return GetChainsSprtLoops(segmentList);
}
List<Chain> retVal = new List<Chain>();
retVal.AddRange(GetChainsSprtFragments(segmentList, pointCounts));
if (segmentList.Count > 0)
{
retVal.AddRange(GetChainsSprtLoops(segmentList));
}
return retVal;
}