[TIL] 117 [C#] list ์š”์†Œ ์ œ๊ฑฐ Remove, RemoveAt, Linq - Skip, Take

์—…๋ฐ์ดํŠธ:

์นดํ…Œ๊ณ ๋ฆฌ:

ํƒœ๊ทธ: ,


list Remove(value) RemoveAt(index) Skip Take



Remove(value)

Remove(value)
list์— value ๊ฐ€ ์žˆ์œผ๋ฉด ๊ทธ ์š”์†Œ๋ฅผ ์ œ๊ฑฐํ•ฉ๋‹ˆ๋‹ค.

RemoveAt(index)

Remove(index)
list์— index ๋ฒˆ์งธ ์š”์†Œ๋ฅผ ์ œ๊ฑฐํ•ฉ๋‹ˆ๋‹ค.

list = {3,6,7};
list.Remove(7);    // ๊ฐ’์ด 7์ธ ์š”์†Œ ์ œ๊ฑฐ
list.RemoveAt(0);  // 0๋ฒˆ์งธ 3 ์ œ๊ฑฐ

// list => {6}





Linq - Skip, Take

๋ฐฐ์—ด์—์„œ ์›ํ•˜๋Š” ๋ถ€๋ถ„ ์ž˜๋ผ๋‚ด๊ธฐ
Skip(x) = ์•ž x๊ฐœ๋ฅผ ๊ฑด๋„ˆ๋œ€
Take(x) = ์•ž x๊ฐœ๋งŒ ํฌํ•จ

int[] arr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
var skip = arr.Skip(7); // ์•ž 7๊ฐœ๋ฅผ ๊ฑด๋„ˆ๋›ฐ๊ณ   {8, 9, 10}
var take = arr.Take(3); // ์•ž 3๊ฐœ๋งŒ ๊ฐ€์ง€๊ณ   {1, 2, 3}


// skip, take ์‚ฌ์šฉ
list = { 1,2,3,4,5,6,7,8,9,10 };
List<int> trimmed = list.Skip(3).Take(3).ToList(); //{4,5,6}
List<int> trimmed = diffs.Skip(upper).Take(testcase - 2 * upper).ToList();





์žก๋‹ด, ์ผ๊ธฐ?

์ด๋ ฅ์„œ ์ •๋ฆฌ, ์ž์†Œ์„œ ์ž‘์„ฑ, ๋ฉด์ ‘์ค€๋น„์ค‘, ์ฝ”ํ…Œ




๐Ÿ“”

๋Œ“๊ธ€๋‚จ๊ธฐ๊ธฐ