C# List

List<T> is a kind of array with flexible length.

using System.Collections.Generic;
using System.Windows.Forms;
List<int> lst = new List<int>();
List<int> lst = new List<int> {4,9,18,3};
MessageBox.Show(lst2.Count.ToString());

Useful List<T> methods:
void lst.Add(int item);
void lst.AddRange(IEnumerable<int> collection);
bool lst.Remove(int item);
void lst.RemoveAt(int index);
bool lst.Contains(int item);
int lst.IndexOf(int item);
void lst.Sort();
void lst.Reverse();

Useful List<T> methods example:
using System.Collections.Generic;
List<int> lst = new List<int> {4,9,18,3};
lst.Add(100); //lst is now 4,9,18,3,100
//-------------------------------
List<int> lst = new List<int> {4,9,18,3};
lst.AddRange(new List<int> { 2, 3 }); //lst is now 4,9,18,3,2,3
//-------------------------------
List<int> lst = new List<int> {4,9,18,3};
lst.Remove(9); //lst is now 4,18,3
//-------------------------------
List<int> lst = new List<int> {4,9,18,3,4};
lst.Remove(4); //lst is now 9,18,3,4
//-------------------------------
List<int> lst = new List<int> {4,9,18,3,4};
lst.RemoveAt(2); //lst is now 4,9,3,4
//-------------------------------
List<int> lst = new List<int> {4,9,18,3,4};
lst.Sort(); //3,4,4,9,18
//-------------------------------
List<int> lst = new List<int> {4,9,18,3,4};
lst.Reverse(); //4,3,18,9,4

List of objects:
class A
{
...
}
A oa1 = new A();
A oa2 = new A();
List<A> lst = new List<A>{oa1,oa2};



endmemo.com © 2017  Terms of Use | Home