본문 바로가기
tips/자주쓰는 C# 스크립트

유니티 C# 자주쓰는 List<T> 메서드

by 디지털 수공업자 2021. 2. 7.
반응형
using System.Linq ;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TestList : MonoBehaviour {

	void Start() {
		
		List<string> fruits = new List<string>() {

			"apple", 
			"orange",
			"apple",
			"melon"

		} ;

		List<string> foods = new List<string>() {

			"rice",
			"apple",
			"cookie"

		} ;

		// List 내부에서 중복 제거
		fruits = fruits.Distinct().ToList();

		// 2개의 List에서 중복 제거
		List<string> FoodsExceptFruits = new List<string>() ;
		FoodsExceptFruits = FoodsExceptFruits.Except(fruits).ToList() ;

		// index 알아내기
		int indexId = fruits.IndexOf("orange") ;


	}

}

 

반응형

댓글