Advertisement
dorabod2006

3_2_list_no_comment

Nov 28th, 2014
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.91 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. public class Example
  5. {
  6.     public static void Main()
  7.     {
  8.         List<string> Chocolate = new List<string>();
  9.  
  10.         Console.WriteLine("\nCapacity: {0}", Chocolate.Capacity);
  11.  
  12.         Chocolate.Add("White chocolate");
  13.         Chocolate.Add("Milk chocolate");
  14.         Chocolate.Add("Dark chocolate");
  15.         Chocolate.Add("Sweet Dark chocolate");
  16.         Chocolate.Add("Semi-sweet chocolate");
  17.        Chocolate.Add("Bittersweet chocolate");
  18.         Console.WriteLine();
  19.         foreach (string chocolate in Chocolate)
  20.         {
  21.             Console.WriteLine(chocolate);
  22.         }
  23.  
  24.         Console.WriteLine("\nCapacity: {0}", Chocolate.Capacity);
  25.         Console.WriteLine("Count: {0}", Chocolate.Count);
  26.  
  27.         Console.WriteLine("\nContains(\"White chocolate\"): {0}",
  28.             Chocolate.Contains("White chocolate"));
  29.  
  30.         Console.WriteLine("\nInsert(2, \"Unsweetened chocolate\")");
  31.         Chocolate.Insert(2, "Unsweetened chocolate");
  32.  
  33.         Console.WriteLine();
  34.         foreach (string chocolate in Chocolate)
  35.         {
  36.             Console.WriteLine(chocolate);
  37.         }
  38.  
  39.        
  40.         Console.WriteLine("\nchocolates[3]: {0}", Chocolate[3]);
  41.  
  42.         Console.WriteLine("\nRemove(\"White chocolate\")");
  43.         Chocolate.Remove("White chocolate");
  44.  
  45.         Console.WriteLine();
  46.         foreach (string chocolate in Chocolate)
  47.         {
  48.             Console.WriteLine(chocolate);
  49.         }
  50.  
  51.         Chocolate.TrimExcess();
  52.         Console.WriteLine("\nTrimExcess()");
  53.         Console.WriteLine("Capacity: {0}", Chocolate.Capacity);
  54.         Console.WriteLine("Count: {0}", Chocolate.Count);
  55.  
  56.         Chocolate.Clear();
  57.         Console.WriteLine("\nClear()");
  58.         Console.WriteLine("Capacity: {0}", Chocolate.Capacity);
  59.         Console.WriteLine("Count: {0}", Chocolate.Count);
  60.  
  61.         Console.ReadLine();
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement