本文整理汇总了C#中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.List
的用法示例。
在下文中一共展示了System.Collections.Generic.List.ForEach方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Use_a_framework_method_that_accepts_a_ActionOfT_delegate
public void Use_a_framework_method_that_accepts_a_ActionOfT_delegate()
{
var samples = new System.Collections.Generic.List<double> { 9, 16, 25, 36 };
// Instantiation
Action<double> printSquareRoot = delegate(double number)
{
Console.WriteLine(Math.Sqrt(number));
};
// Invocation
samples.ForEach(printSquareRoot);
}
示例2: spawnPlanetsBlack
void spawnPlanetsBlack(int numPlanets)
{
Vector3 spawnPos = Vector3.zero;
float zOffset = 0;
bool needStation = true;
int wantAsteroid = 0;
for(int i=0; i<numPlanets; i++)
{
zOffset += Random.Range(12f, 18f);
spawnPos = new Vector3(center.x, 0, center.z + zOffset);
AddToList(spawnPos);
if (needStation && (Random.Range(0, 3) == 0 || i == numPlanets - 2))
{
needStation = false;
spawnSpaceStationBlack(spawnPos);
continue;
}
// if (wantAsteroid < 2 && Random.Range(0, 3) == 0 && i != numPlanets - 1)
// {
// wantAsteroid++;
// spawnAsteroidFieldBlack(spawnPos);
// continue;
// }
GameObject planet = makePlanetBlack(spawnPos);
GameObject myPlanet = (GameObject)Instantiate(planet, center, Quaternion.identity);
float yRotation = Random.Range(0f, 330f);
myPlanet.transform.Rotate(Vector3.up, yRotation);
Vector3 tempPos = myPlanet.transform.GetChild(0).position;
int hasMoon = Random.Range(0, 2);
if(hasMoon == 0)
{
//spawnMoon(planet.transform.GetChild(0).transform, spawnPos);
var children = new System.Collections.Generic.List<GameObject>();
foreach(Transform child in myPlanet.transform.FindChild("Planet 0"))
children.Add(child.gameObject);
children.ForEach(child => Destroy(child));
}
}
}
示例3: spawnPlanetsWhite
void spawnPlanetsWhite(int numPlanets)
{
Vector3 spawnPos = Vector3.zero;
for(int i=0; i<numPlanets; i++)
{
int spawnX = Random.Range(START_GAME_AREA, MAX_GAME_AREA + 1);
int spawnY = Random.Range(START_GAME_AREA, MAX_GAME_AREA + 1);
spawnPos = new Vector3(spawnX, 0, spawnY);
while (!isAvailable(spawnPos))
{
spawnX = Random.Range(START_GAME_AREA, MAX_GAME_AREA + 1);
spawnY = Random.Range(START_GAME_AREA, MAX_GAME_AREA + 1);
spawnPos = new Vector3(spawnX, 0, spawnY);
}
AddToList(spawnPos);
GameObject planet = makePlanet(spawnPos);
GameObject myPlanet = (GameObject)Instantiate(planet, center, Quaternion.identity);
int hasMoon = Random.Range(0, 2);
if(hasMoon == 0)
{
//spawnMoon(planet.transform.GetChild(0).transform, spawnPos);
var children = new System.Collections.Generic.List<GameObject>();
foreach(Transform child in myPlanet.transform.FindChild("Planet 0"))
children.Add(child.gameObject);
children.ForEach(child => Destroy(child));
}
}
}
示例4: removeNotifications
public JsonResult removeNotifications(string[] notificationsId)
{
JsonResult result = null;
bool bResult = true;
if (notificationsId != null && notificationsId.Length > 0)
{
System.Collections.Generic.List<Notification> notifications = new System.Collections.Generic.List<Notification>();
notifications = db.Notification.Where(n => notificationsId.Contains(n.Id.ToString())).ToList();
notifications.ForEach(notif => db.Notification.Remove(notif));
db.SaveChanges();
}
else
bResult = false;
result = new JsonResult()
{
Data = new
{
Result = bResult
}
};
return result;
}