【Unity】(C#)用最简单的程序帮助新手理解Func<T,TResult>的用法
using System;
using UnityEngine;
public class Test : MonoBehaviour
{
Func<int, string> selector = str => (str + 1).ToString();
// Start is called before the first frame update
void Start()
{
Debug.Log(selector(1));
}
}
怎么样,是不是很简单,再来个枚举版本的
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public class Test : MonoBehaviour
{
Func<string, string> selector = str => (str + "1");
// Start is called before the first frame update
void Start()
{
string[] strings = { "1", "2", "3", "4", "5", "6", };
IEnumerable<string> meiju = strings.Select(selector);
foreach (string s in meiju)
{
Debug.Log(s);
}
}
}