比较简单就不啰嗦了,直接上段小代码,清晰明了!
using System.Collections; using System.Collections.Generic; using UnityEngine; public class T_test : MonoBehaviour { private void Start() { Test<int>(); Debug.Log("-------------"); Test<string>(); } private void Test<T>() { if (Types.Equals(typeof(T),typeof(int))) { Debug.Log("调用的类型是 int"); } else if (Types.Equals(typeof(T), typeof(string))) { Debug.Log("调用的类型是 string"); } } }
运行结果: