本文整理汇总了C#中GenericList类的典型用法代码示例。如果您正苦于以下问题:C# GenericList类的具体用法?C# GenericList怎么用?C# GenericList使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GenericList类属于命名空间,在下文中一共展示了GenericList类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main()
{
GenericList<string> glist = new GenericList<string>();
glist.Add("First");
glist.Add("Second");
glist.Add("Third");
glist.Add("Pesho");
glist.Add("Gosho");
glist.Add("Tosho");
glist.Insert(0, "Purvi Pesho");
Console.WriteLine(glist);
Console.WriteLine("Index of \"Second\": {0}", glist.IndexOf("Second"));
Console.WriteLine("Does contain \"Toshkata\": {0}", glist.Contains("Toshkata"));
Console.WriteLine("Does contain \"Pesho\": {0}", glist.Contains("Pesho"));
Console.WriteLine();
glist.Remove(2);
glist.Remove(2);
Console.WriteLine(glist);
Console.WriteLine("Min Value: {0}", glist.Min());
Console.WriteLine("Max Value: {0}", glist.Max());
glist.Clear();
Console.WriteLine(glist);
}
示例2: Main
static void Main()
{
GenericList<int> testList = new GenericList<int>(5);
testList.Add(5);
testList.Add(45);
testList.Add(18);
testList.Add(66);
testList.Add(22);
testList.Add(6);
testList.Add(2);
testList.Add(9);
testList.Add(10);
Console.WriteLine("tstList.Count ->{0}",testList.Count);
Console.WriteLine(testList.ToString());
testList.RemoveAt(3);
Console.WriteLine("After removing an element:");
Console.WriteLine("tstList.Count ->{0}", testList.Count);
Console.WriteLine(testList.ToString());
testList.InsertAt(3, 66);
Console.WriteLine("After inserting an element:");
Console.WriteLine("tstList.Count ->{0}", testList.Count);
Console.WriteLine(testList.ToString());
Console.WriteLine();
Console.WriteLine("searching for element:");
int position=testList.FindByValue(66);
Console.WriteLine("The element is on position {0}", position);
position = testList.Min();
Console.WriteLine("The Min Element in list is {0}",position);
position = testList.Max();
Console.WriteLine("The Max Element in list is {0}",position);
}
示例3: Main
static void Main()
{
GenericList<int> numbers = new GenericList<int>()
{
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20
};
Console.WriteLine("Creating a GenericList with the numbers from 1 to 20 \n {0} \n", numbers);
numbers.Remove(19);
Console.WriteLine("Removing the 19th element \n {0} \n", numbers);
numbers.Add(100);
Console.WriteLine("Adding an element to the end of the GenericList \n {0} \n", numbers);
numbers.Insert(30, 10);
Console.WriteLine("Inserting an element on the 10th position \n {0} \n", numbers);
numbers[3] = 9;
Console.WriteLine("Changing the value of the 3rd index number \n {0} \n", numbers);
Console.WriteLine("Trying to find number 4 \n Number Found: {0}, Found At: {1} \n", numbers.Contains(4), numbers.Find(4));
Console.WriteLine("Trying to find number 80 \n Number Found: {0}, Found At: {1} \n", numbers.Contains(80), numbers.Find(80));
Console.WriteLine("Min element: {0}, Max element: {1} \n", numbers.Min(), numbers.Max());
numbers.Clear();
Console.WriteLine("Cleared GenericList: \n {0} \n", numbers);
Type type = typeof(GenericList<>);
VersionAttribute attribute = (VersionAttribute)type.GetCustomAttributes(false).LastOrDefault();
Console.WriteLine("Version: " + attribute.Version);
}
示例4: Main
public static void Main()
{
GenericList<int> list = new GenericList<int>(4);
Console.WriteLine("Add , auto-grow and ToString() test");
Console.WriteLine();
// Testing add method and auto-grow
for (int i = 1; i <= 20; i++)
{
list.Add(i);
}
Console.WriteLine(list.ToString());
AddSeparator();
// Add 100 on position 5
Console.WriteLine("Test insert at position (insert 100 on position 5)");
Console.WriteLine();
list.Add(100, 5);
Console.WriteLine(list.ToString());
AddSeparator();
// Test min and max
Console.WriteLine("Min --> {0}", list.Min());
Console.WriteLine("Max --> {0}", list.Max());
AddSeparator();
// Indexer test
Console.WriteLine("Indexer test:");
Console.WriteLine("list[5] --> {0}", list[5]);
AddSeparator();
}
示例5: Main
static void Main(string[] args)
{
Console.WriteLine(typeof(GenericList<>).GetCustomAttribute(typeof(Ver)));
GenericList<string> list = new GenericList<string>();
GenericList<Point2D> list2 = new GenericList<Point2D>();
list2.Add(new Point2D(5, 3));
list2.Add(new Point2D(6, 4));
list.Add("az");
list.Add("ti");
list.Add("toj");
list.Add("tq");
list.Insert("to",1);
list.Remove(3);
for (int i = 0; i < list.Count; i++)
{
Console.WriteLine(list[i]);
}
Console.WriteLine(Environment.NewLine);
Console.WriteLine(list.FindIndexOf("toj"));
Console.WriteLine(list);
Console.WriteLine(list.Contains("tq"));
Console.WriteLine(list.Max());
Console.WriteLine(list2.Max());
Console.WriteLine(list2.Contains(new Point2D(5, 3)));
Console.WriteLine(list2.Contains(new Point2D(5, 2)));
}
示例6: Main
static void Main()
{
try
{
GenericList<int> list = new GenericList<int>(5);
list.Add(1);
list.Add(2);
list.Add(1);
Console.Write("Add : ");
Console.WriteLine(list.ToString());
list.Remove(1);
Console.Write("Remove : ");
Console.WriteLine(list.ToString());
list.Insert(3, 555);
Console.Write("Insert : ");
Console.WriteLine(list.ToString());
Console.Write("Clear : ");
list.ClearList();
Console.WriteLine(list.ToString());
Console.WriteLine("Searching element by its value");
list.Add(1);
list.Add(2);
list.Add(1);
list.Add(2);
list.Insert(2, 3);
Console.WriteLine(list.ToString());
int indexOfElement = list.FindElement(1, 1);
Console.WriteLine(indexOfElement);
}
catch (ArgumentOutOfRangeException exp)
{
Console.WriteLine("Error!");
Console.WriteLine(exp);
}
}
示例7: Main
static void Main()
{
GenericList<int> nums = new GenericList<int>() { 1, 2, 5, 7 };
Console.WriteLine("All elements: " + nums.ToString());
Console.WriteLine("Num at index 1: " + nums[1]);
nums.Remove(0);
Console.WriteLine("Element at index 0 has been removed");
Console.WriteLine("Num at index 1: " + nums[1]);
Console.WriteLine("The index of 5 is: " + nums.Find(5));
Console.WriteLine("Nums contains 7? " + nums.Contains(7));
for (int index = 0; index < 50; index++)
{
nums.Add(9);
Console.Write("Element added: " + nums[nums.Count - 1]);
Console.WriteLine(" Count: " + nums.Count + " Capacity: " + nums.Capacity);
}
nums.Insert(14, 0);
nums.Insert(14, 0);
nums.Insert(14, 0);
nums.Insert(20, 20);
Console.WriteLine(nums);
Console.WriteLine("Min: " + nums.Min());
Console.WriteLine("Max: " + nums.Max());
Console.WriteLine("The version of this class is: " + nums.Version());
}
示例8: Main
static void Main()
{
// Declare a list of type int
GenericList<int> intList = new GenericList<int>();
intList.Add(1);
intList.Add(2);
intList.Add(3);
Console.WriteLine("Number of elements: {0}", intList.Count);
for (int i = 0; i < intList.Count; i++)
{
int element = intList[i];
Console.WriteLine(element);
}
Console.WriteLine();
// Declare a list of type string
GenericList<string> stringList = new GenericList<string>();
stringList.Add("C#");
stringList.Add("Java");
stringList.Add("PHP");
stringList.Add("SQL");
Console.WriteLine("Number of elements: {0}", stringList.Count);
for (int i = 0; i < stringList.Count; i++)
{
string element = stringList[i];
Console.WriteLine(element);
}
}
示例9: Main
static void Main()
{
IGenericList<decimal> decimals = new GenericList<decimal>();
decimals.Add(0.0001m);
Console.WriteLine(decimals);
Console.WriteLine(decimals.Version());
}
示例10: Main
static void Main()
{
GenericList<int> list = new GenericList<int>(5);
StringBuilder result = new StringBuilder();
list.Add(3);
list.InsertAt(0, 2);
list.InsertAt(0, 1);
result.AppendLine(list.ToString());
result.AppendLine(String.Format("Count: {0}", list.Count));
result.AppendLine("--REMOVE AT INDEX 1--");
list.RemoveAt(1);
result.AppendLine(list.ToString());
result.AppendLine(String.Format("Count: {0}", list.Count));
result.AppendLine(" MIN: " + list.Min());
result.AppendLine(" MAX: " + list.Max());
result.AppendLine("-----INDEX OF 3-----");
result.AppendLine(list.IndexOf(3).ToString());
result.AppendLine("-----INDEX OF 2-----");
result.AppendLine(list.IndexOf(2).ToString());
result.AppendLine("-----CLEAR LIST-----");
list.Clear();
result.AppendLine(list.ToString());
result.AppendLine(String.Format("Count: {0}", list.Count));
Console.WriteLine(result);
}
示例11: Main
static void Main()
{
//Create new list of strings and show functionality
GenericList<string> myList = new GenericList<string>(10);
myList[0] = "My";
myList[1] = "name";
myList[2] = "is";
myList[3] = "Svetlin";
myList[4] = "Nakov";
Console.WriteLine(myList);
myList.Add("I like beer!");
Console.WriteLine(myList[5]);
myList.RemoveByIndex(2); // remove 'is'
Console.WriteLine(myList[2]); //print 'Svetlin'
myList.Insert(2, "my name");
Console.WriteLine(myList[2]);
Console.WriteLine(myList.IndexOfElement("name",0)); // print '1'
Console.WriteLine();
Console.WriteLine(myList);
myList[7] = "aaa";
myList[8] = "bbb";
myList[9] = myList.Max(myList[7], myList[8]);
Console.WriteLine(myList[9]); //print 'bbb'
//Create new list of strings and show functionality
GenericList<int> otherList = new GenericList<int>(3);
Console.WriteLine(otherList[0]);
}
示例12: Main
static void Main()
{
GenericList<int> nums = new GenericList<int>();
nums.Add(5);
nums.Add(10);
nums.Add(50);
Console.WriteLine(nums.Contains(10)); // output: True
Console.WriteLine(nums[2]); // output: 50
nums[2] = 42;
Console.WriteLine(nums[2]); // output: 42
Console.WriteLine(nums.IndexOf(42)); // output: 2
Console.WriteLine(nums.Count); // output: 3
Console.WriteLine(nums); // output: [item1, item2...]
nums.RemoveAt(0);
Console.WriteLine(nums.Count); // output: 2
nums.Clear();
Console.WriteLine(nums.Count); // output: 0
}
示例13: Main
static void Main(string[] args)
{
GenericList<int> test = new GenericList<int>(1);
test.Add(2);
test.Add(45);
test.Add(4);
test.Add(50);
test.Add(0);
test.Add(-1000);
Console.WriteLine(test);
test.Remove(4);
Console.WriteLine(test);
test.Insert(0, 560);
Console.WriteLine(test);
Console.WriteLine(test.Find(123));
Console.WriteLine(test.Max());
Console.WriteLine(test.Min());
test.Clear();
Console.WriteLine(test);
}
示例14: Main
public static void Main(string[] args)
{
var l = new GenericList<int>();
l.Add(3);
l.Add(4);
l.Add(235252532);
Console.WriteLine(l);
l.Insert(1, 2);
Console.WriteLine(l);
Console.WriteLine(l.Find(4));
l.RemoveAt(1);
Console.WriteLine(l);
l.Add(1);
l.Add(7);
l.Add(1);
l.Add(9);
l.Add(3);
l.Add(2);
l.Add(6);
l.Add(8);
Console.WriteLine(l);
Console.WriteLine(l.Min());
Console.WriteLine(l.Max());
l.Clear();
Console.WriteLine(l);
}
示例15: EmptyListSetCapacityTest
public void EmptyListSetCapacityTest()
{
GenericList<int> list = new GenericList<int>(17);
Assert.AreEqual((uint)0, list.Count);
Assert.AreEqual((uint)17, list.Capacity);
}