using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// lambda表达式
/// </summary>
namespace LambdaTest
{
public class Lambda : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
Show();
}
void Show()
{
{
ABC<string> a = new ABC<string>(Test1);
a("1");
}
{
ABC<string> a = new ABC<string>((delegate (string b)
{
Debug.LogError("测试2");
}));
a("1");
}
{
ABC<string> a = new ABC<string>((string b) =>
{
Debug.LogError("测试3");
});
a("1");
}
{
Action action = () => Debug.LogError("无参数测试4");
Action<DateTime> action1 = (DateTime d) => Debug.LogError($"{d}参数");
action1(DateTime.Now);
Func<DateTime> func = () => DateTime.Now;
DateTime a = func();
Debug.LogError(a);
}
}
public void Test1(string a)
{
Debug.LogError("测试1");
}
}
delegate void ABC<T>(T abc);
}
lambda表达式
最新推荐文章于 2024-10-10 22:26:03 发布