比較簡單就不囉嗦了,直接上段小代碼,清晰明瞭!
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");
}
}
}
運行結果: