一边遍历list 可以用for 或者foreach去操作,后来发现list本身就有迭代的方法,ForEach
查看MSDN的介绍:ForEach 本身要传一个Action的委托
官方例子:
using System;
using System.Collections.Generic;
class Program
{
static void Main()
{
List<String> names = new List<String>();
names.Add("Bruce");
names.Add("Alfred");
names.Add("Tim");
names.Add("Richard");
// Display the contents of the list using the Print method.
names.ForEach(Print);
// The following demonstrates the anonymous method feature of C#
// to display the contents of the list to the console.
names.ForEach(delegate(String name)
{
Console.WriteLine(name);
});
}
private static void Print(string s)
{
Console.WriteLine(s);
}
}
xfcTarget :参数
public List<GameObject> XFCTargets = new List<GameObject>();
XFCTargets.ForEach(xfcTarget =>
{
if (xfcTarget) xfcTarget.SetActive(active);
});