using System.Collections.Generic;
using UnityEngine;
public class Main : MonoBehaviour{
void Start(){
string[] strs=new string[]{"a","b","c","a","e","c","","f",""};
List<string> list=new List<string>(strs);
List<string> layerNameList=new List<string>(strs);
for (int i=0; i<layerNameList.Count;i++){
for (int j=layerNameList.Count-1;j>i;j--){
if (layerNameList[i]==layerNameList[j]){
layerNameList.RemoveAt(j);
}
}
}
/*for (int i=0; i<layerNameList.Count;i++){
Debug.Log(layerNameList[i]);
}*/
}
}
使用Enumerable.Distinct方法
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public class Test:MonoBehaviour{
private void Start(){
string[] strs=new string[]{"a","b","c","a","e","c","","f",""};
List<string> list=strs.Distinct().ToList();//using System.Linq;
/*for (int i=0; i<list.Count;i++){
Debug.Log(list[i]);
}*/
}
}