【C#】List<T>.ForEach 方法
一边遍历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);
});声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。
- 上一篇: 【UGUI】UGUI 基础知识(代码设置锚点)
- 下一篇:没有了
