namespace List { class Program { static void Main(string[] args) { List<int> list = new List<int>(new int[] { 19, 23, 29 }); int index = list.IndexOf(23); // Check if 23 Exists. Console.WriteLine(index); index = list.IndexOf(10); // Does not exist. Console.WriteLine(index); list.Add(35); list.Insert(1, 40); list.Remove(23); // RemoveAt(index) method, or the Remove(obj) list.RemoveAt(0); // RemoveAt(index) method, or the Remove(obj) foreach (int x in list) { Console.WriteLine(x); } Console.ReadLine(); } } }
沒有留言:
張貼留言