C # List of removing duplicate items

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]);
        }

    }
}

Guess you like

Origin www.cnblogs.com/kingBook/p/11291908.html