How to remove an item from a list in c #

I have this code programming gives me a friend:

"While (true)
{
List Letters = new List (26);

foreach (int letters in LetrasU)
{
TeclaAEvaluar KeyCode = (KeyCode) letters;
if (Input.GetKeyDown (teclaAEvaluar) == true)
{
LetrasU.Remove (letters);

}
}

} "

Also I have one list which eliminates each key generated with a “random” and these keys can not be repeated.

All my code is as follows:

void Start () {

List LetrasU = new List (25);

LetrasU.Add (97);
LetrasU.Add (98);
LetrasU.Add (99);
LetrasU.Add (101);
LetrasU.Add (102);
LetrasU.Add (103);
LetrasU.Add (104);
LetrasU.Add (105);
LetrasU.Add (106);
LetrasU.Add (107);
LetrasU.Add (108);
LetrasU.Add (109);
LetrasU.Add (110);
LetrasU.Add (111);
LetrasU.Add (112);
LetrasU.Add (113);
LetrasU.Add (114);
LetrasU.Add (115);
LetrasU.Add (116);
LetrasU.Add (117);
LetrasU.Add (118);
LetrasU.Add (119);
LetrasU.Add (120);
LetrasU.Add (121);
LetrasU.Add (122);

while (true)
{
List Letters = new List (25);

foreach (int letters in LetrasU)
{
TeclaAEvaluar KeyCode = (KeyCode) letters;
if (Input.GetKeyDown (teclaAEvaluar) == true)
{
LetrasU.Remove (letters);

}

if (Input.GetKeyDown (teclaAEvaluar) == false)
{
Application.LoadLevel (2);
}

}

}

}

// Update is called eleven per frame
void Update () {

}

}

1 Like

try looking into List<T>.RemoveAt(Int32) Method (System.Collections.Generic) | Microsoft Learn

Not looking at your code because 1. it’s gross. 2. didn’t use code tags.

use List.Remove(index)

5 Likes

First, use code tags:

Second, look into the link Rob21894 gave you for removing at a specific index.

And for removing specific values just use Remove:

this answer messed me up. Should use List.Remove(item) or use List.RemoveAt(item index)

3 Likes

haha unless it was a list of indices :slight_smile: