list.ForEach AsReadOnly

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 using System.Diagnostics;
 7 
 8 namespace ConsoleApplication7
 9 {
10     class Program
11     {
12         static void Main(string[] args)
13         {
14             List<Per> list = new List<Per>();
15             list.Add(new Per(1));
16             list.Add(new Per(2));
17             list.Add(new Per(3));
18 
19             var ReadOnlyList = list.AsReadOnly(); //  集合只读
20 
21             list.ForEach(x => Console.WriteLine(x.Id));  //  遍历
22             Console.ReadKey();
23 
24         }
25     }
26 
27 
28 
29 
30     class Per
31     {
32 
33 
34         public Per(int id)
35         {
36             this.Id = id;
37         }
38 
39         public int Id { get; set; }
40 
41 
42     }
43 }

 

posted @ 2016-10-20 14:15  刀小爱  阅读(289)  评论(0)    收藏  举报