Advertisement
Guest User

Untitled

a guest
Oct 1st, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.39 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5.  
  6. public class Program
  7. {
  8. public static void Main()
  9. {
  10. //Array
  11. /*int[] java = new int[] { 70, 88, 30 };
  12. //Array.Sort(java);
  13. foreach(int i in java){
  14. Console.WriteLine(i);
  15. }
  16. */
  17.  
  18. //ArrayList
  19. /*
  20. ArrayList myArray = new ArrayList();
  21. myArray.Add("Abisola");
  22. myArray.Add("Java");
  23. myArray.Add("Apple");
  24. myArray.Add(10);
  25. myArray.Add(33);
  26. myArray.Add(56);
  27. myArray.Add(12);
  28. myArray.Add(23);
  29. //myArray.Sort();
  30.  
  31.  
  32. Console.WriteLine("myArray has {0} Capacity", myArray.Capacity);
  33. Console.WriteLine("myArray has {0} Element", myArray.Count);
  34. myArray.RemoveAt(3);
  35. Console.WriteLine("\nThe elements in my array are:");
  36. foreach (object j in myArray){
  37. Console.WriteLine(j);
  38. }
  39. myArray.Reverse();
  40. myArray.Insert(3, 10);
  41. Console.WriteLine("\nReversed list with additonal element");
  42. foreach (object j in myArray){
  43. Console.WriteLine(j);
  44. }
  45.  
  46. int[] statistics = new int[] { 76, 40, 90 };
  47. foreach(int j in statistics){
  48. myArray.Add(j);
  49. }
  50.  
  51. myArray.AddRange(java);
  52. Console.WriteLine("\n");
  53.  
  54. foreach (object j in myArray){
  55. Console.WriteLine(j);
  56. }
  57. Console.WriteLine("\nPrint out only strings");
  58. foreach (object u in myArray){
  59. if (u is string){
  60. Console.WriteLine("I am a String: {0}", u);
  61. }
  62. }
  63.  
  64. */
  65.  
  66. //List
  67. /*
  68. List<int> myList = new List<int>();
  69. myList.Add(78);
  70. myList.Add(95);
  71. myList.Add(23);
  72. myList.Add(15);
  73. myList.Add(23);
  74. Console.WriteLine("\nMy new List");
  75. foreach(int i in myList){
  76. Console.WriteLine(i);
  77. }
  78. myList.Sort();
  79. Console.WriteLine("\nMy sorted List");
  80. foreach(int i in myList){
  81. Console.WriteLine(i);
  82. }
  83.  
  84. Console.WriteLine("\nMy List Sum is: "+ myList.Sum());
  85.  
  86. Console.WriteLine("\nMy Distinct List contains: ");
  87. List<int> newList = myList.Distinct().ToList();
  88. foreach(int i in newList){
  89. Console.WriteLine(i);
  90. }
  91. */
  92.  
  93. //Linked List
  94.  
  95. /*
  96. LinkedList<string> myLink = new LinkedList<string>();
  97. myLink.AddLast("Stephen");
  98. myLink.AddLast("Hatem");
  99. myLink.AddLast("Emmanuel");
  100. myLink.AddFirst("Gordon");
  101. Console.WriteLine("My Linked List contains");
  102.  
  103. foreach (var i in myLink)
  104. {
  105. Console.WriteLine(i);
  106. }
  107. */
  108.  
  109. //Dictionary
  110. /*
  111. Dictionary<string, int> myDictionary = new Dictionary<string, int>();
  112. myDictionary.Add("Age", 25);
  113. myDictionary.Add("Grade", 80);
  114.  
  115. Console.WriteLine("\nAge is {0}", myDictionary["Age"]);
  116. List<string> myKey = new List<string>(myDictionary.Keys);
  117. for (int i = 0; i < myKey.Count; i++)
  118. {
  119. int myInt = myDictionary[myKey[i]];
  120. Console.WriteLine(myInt);
  121.  
  122. }
  123. */
  124.  
  125. //Hastable
  126. /*
  127. Hashtable myHash = new Hashtable();
  128. myHash["Name"] = "Abisola";
  129. myHash[1] = "Name";
  130. myHash[3] = "is";
  131. myHash[2] = "my";
  132. //myHash.Add("Grade", 80);
  133. Console.WriteLine("Hashtable contains {0} elements \nAnd they are: ", myHash.Count);
  134. foreach (DictionaryEntry entry in myHash)
  135. {
  136. Console.WriteLine("{0}, {1}", entry.Key, entry.Value);
  137. }
  138. */
  139.  
  140. //Stack
  141. /*
  142. Declaration types
  143. Stack myStack = new Stack();
  144. Stack<string> myStack = new Stack<string>();
  145. */
  146. /*
  147. Stack<string> myStack = new Stack<string>();
  148. myStack.Push("Chanel");
  149. myStack.Push("Prada");
  150. myStack.Push("Gucci");
  151. Console.WriteLine();
  152. Console.WriteLine("My Top Value is "+myStack.Peek());
  153. Console.WriteLine();
  154. Console.WriteLine(myStack.Pop());
  155. Console.WriteLine();
  156. Console.WriteLine("My Top Value is "+myStack.Peek()+"\n");
  157. foreach(string s in myStack)
  158. {
  159. Console.WriteLine(s);
  160. }
  161. */
  162.  
  163. /*
  164. Stack myStack = new Stack();
  165. myStack.Push("Chanel");
  166. myStack.Push("Prada");
  167. myStack.Push("Gucci");
  168. Console.WriteLine();
  169. Console.WriteLine("My Top Value is "+myStack.Peek());
  170. Console.WriteLine();
  171. Console.WriteLine(myStack.Pop());
  172. Console.WriteLine();
  173. Console.WriteLine("My Top Value is "+myStack.Peek());
  174. */
  175.  
  176. //Queue
  177. /*
  178. Queue<int> myQueue = new Queue<int>();
  179. myQueue.Enqueue(5);
  180. myQueue.Enqueue(10);
  181. myQueue.Enqueue(15);
  182. myQueue.Enqueue(20);
  183. foreach (int i in myQueue)
  184. {
  185. Console.WriteLine(i);
  186. }
  187. */
  188.  
  189. }
  190. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement