c# Array或List有個很實用的ForEach方法,可以直接傳入一個方法對集合中元素操作


using System;
using System.Collections.Generic;

namespace demo
{
    class Program
    {
        static void Main(string[] args)
        {
            List<String> names = new List<String>();
            names.Add("Bruce");
            names.Add("Alfred");
            names.ForEach(Print);
            names.ForEach(delegate (String name)
            {
                Console.WriteLine(name);
            });
        }
        private static void Print(string s) {
            Console.WriteLine(s);
        }

    }
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM