当前位置: 首页>>代码示例>>C#>>正文


C# System.Collections.Generic.List.ForEach方法代码示例

本文整理汇总了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);            
        }
开发者ID:Gamu9,项目名称:Driven.SimpleSamples.Dotnet,代码行数:13,代码来源:3.+Using+anonymous+methods.cs

示例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));
            }
        }
    }
开发者ID:ThomasCulotta,项目名称:VGD16,代码行数:43,代码来源:MenuSystem.cs

示例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));
            }
        }
    }
开发者ID:ThomasCulotta,项目名称:VGD16,代码行数:31,代码来源:MenuSystem.cs

示例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;
        }
开发者ID:emacho,项目名称:HorizonCMS,代码行数:27,代码来源:DashboardController.cs


注:本文中的System.Collections.Generic.List.ForEach方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。