加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

C# 去除List中的重复项

发布时间:2020-12-15 19:52:56 所属栏目:百科 来源:网络整理
导读:using System.Collections.Generic;using UnityEngine;public class Main : MonoBehaviour{ void Start(){ string[] strs=new string[]{"a","b","c","a","e","","f",""}; Liststring list=new Liststring(strs); Liststring layerNameList=new Liststring(st
using System.Collections.Generic;
using UnityEngine;
public class Main : MonoBehaviour{
    void Start(){
        string[] strs=new string[]{"a","b","c","a","e","","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]);
        }

    }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读