本文整理汇总了C#中System.Collections.Generic.System.Collections.Generic.List.ForEach方法的典型用法代码示例。如果您正苦于以下问题:C# System.Collections.Generic.List.ForEach方法的具体用法?C# System.Collections.Generic.List.ForEach怎么用?C# System.Collections.Generic.List.ForEach使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Generic.System.Collections.Generic.List
的用法示例。
在下文中一共展示了System.Collections.Generic.List.ForEach方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Random
public void Random()
{
BinaryTree<int> Tree = new BinaryTree<int>();
System.Collections.Generic.List<int> Values = new System.Collections.Generic.List<int>();
System.Random Rand = new System.Random();
for (int x = 0; x < 10; ++x)
{
int Value = Rand.Next();
Values.Add(Value);
Tree.Add(Value);
}
for (int x = 0; x < 10; ++x)
{
Assert.Contains(Values[x], Tree);
}
Values.Sort();
StringBuilder Builder = new StringBuilder();
Values.ForEach((x) => Builder.Append(x.ToString() + " "));
Assert.Equal(Builder.ToString(), Tree.ToString());
}
示例2: RemoveEventBookedProductAndCharges
private void RemoveEventBookedProductAndCharges(EventBookedProductModel product)
{
_eventsDataUnit.EventChargesRepository.Delete(product.EventCharge.EventCharge);
_eventsDataUnit.EventBookedProductsRepository.Delete(product.EventBookedProduct);
var eventCharges = new System.Collections.Generic.List<EventChargeModel>();
_event.EventCharges.ForEach(eventCharge =>
{
if (eventCharge.EventCharge.ID == product.EventCharge.EventCharge.ID)
{
eventCharges.Add(eventCharge);
}
});
eventCharges.ForEach(echarge => _event.EventCharges.Remove(echarge));
_event.EventBookedProducts.Remove(product);
}
示例3: createMinionAndTowerButtons
public void createMinionAndTowerButtons()
{
var children = new System.Collections.Generic.List<GameObject>();
foreach (Transform child in createMinionTowerContainer.transform)
children.Add(child.gameObject);
children.ForEach(child => GameObject.Destroy(child));
int btnIndex = 0;
button_CreateTower.SetActive(true);
button_CreateMinion.SetActive(true);
// sort minions order by cost
List<Type> minionsSortedByCost = new List<Type>();
for (int j = 0; j < PlayerMe.availableMinionTypes.Count; j++)
if (TypeIdGeneratorGUI.minionGuiInst.ContainsKey(TypeIdGenerator.getMinionId(PlayerMe.availableMinionTypes[j])))
minionsSortedByCost.Add(PlayerMe.availableMinionTypes[j]);
minionsSortedByCost.Sort( delegate(Type t1, Type t2) {
Minion m1 = TypeIdGenerator.getMinionClass(TypeIdGenerator.getMinionId(t1));
Minion m2 = TypeIdGenerator.getMinionClass(TypeIdGenerator.getMinionId(t2));
if (m1.getCost() < m2.getCost()) return -1;
else return 1;
});
foreach(Type minionType in minionsSortedByCost)
{
int minionTypeId = TypeIdGenerator.getMinionId(minionType);
if(TypeIdGeneratorGUI.minionGuiInst.ContainsKey(minionTypeId))
{
GameObject button = (GameObject)GameObject.Instantiate(button_CreateMinion);
button.transform.parent = createMinionTowerContainer.transform;
button.transform.localScale = new Vector3(1, 1, 1);
button.transform.localPosition = button_CreateMinion.transform.localPosition + new Vector3(50 * btnIndex, 0, 0);
UIButtonMessage[] button_messages = button.GetComponents<UIButtonMessage>();
foreach (var btn_msg in button_messages)
btn_msg.parameter = minionTypeId.ToString();
IMinionGUI minionGUI = TypeIdGeneratorGUI.minionGuiInst[minionTypeId];
minionGUI.drawCreateMinionButtonGUI(button);
towerAndMinionButtons.Add(minionType, button);
btnIndex++;
}
}
// sort towers order by cost
List<Type> towersSortedByCost = new List<Type>();
for (int j = 0; j < PlayerMe.availableTowerTypes.Count; j++)
if (TypeIdGeneratorGUI.towerGuiInst.ContainsKey(TypeIdGenerator.getTowerId(PlayerMe.availableTowerTypes[j])))
towersSortedByCost.Add(PlayerMe.availableTowerTypes[j]);
towersSortedByCost.Sort(delegate(Type t1, Type t2)
{
Tower m1 = TypeIdGenerator.getTowerClass(TypeIdGenerator.getTowerId(t1));
Tower m2 = TypeIdGenerator.getTowerClass(TypeIdGenerator.getTowerId(t2));
if (m1.getCost() < m2.getCost()) return -1;
else return 1;
});
btnIndex = 0;
foreach(Type towerType in towersSortedByCost)
{
int towerTypeId = TypeIdGenerator.getTowerId(towerType);
if(TypeIdGeneratorGUI.towerGuiInst.ContainsKey(towerTypeId))
{
GameObject button = (GameObject)GameObject.Instantiate(button_CreateTower);
button.transform.parent = createMinionTowerContainer.transform;
button.transform.localScale = new Vector3(1, 1, 1);
button.transform.localPosition = button_CreateTower.transform.localPosition + new Vector3(50 * btnIndex, 0, 0);
UIButtonMessage[] button_messages = button.GetComponents<UIButtonMessage>();
foreach (var btn_msg in button_messages)
btn_msg.parameter = towerTypeId.ToString();
ITowerGUI towerGUI = TypeIdGeneratorGUI.towerGuiInst[towerTypeId];
towerGUI.drawCreateTowerButtonGUI(button);
towerAndMinionButtons.Add(towerType, button);
btnIndex++;
}
}
button_CreateTower.SetActive(false);
button_CreateMinion.SetActive(false);
}