C# List.ForEach 方法

竟然有人这样写-循环----看的我很难受-----
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AppExample
{
    class Program
    {
        static void Main(string[] args)
        {
            List numbers = new List();
            numbers.Add(1);
            numbers.Add(2);
            numbers.Add(3);
            numbers.Add(4);
            numbers.Add(5);
            numbers.Add(6);

            //numbers.ForEach(Display);

            //numbers.ForEach(number =>
            //{
            //    Console.WriteLine(number);
            //});
            numbers.ForEach(delegate(int number)
            {
                Console.WriteLine(number);
            });
        }

        static void Display(int number)
        {
            Console.WriteLine(number);
        }
    }
}

 

 

你可能感兴趣的:(Unity,C#)