Advertisement
Coinage

Lists

May 7th, 2015
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.56 KB | None | 0 0
  1. // How to set lists
  2.  
  3. // Lists are important for holding an int or a string as a list.
  4.  
  5. // Example:
  6.  
  7. List<int> list = new List<int>();  // This is a list called list, and each list has to be an int
  8.  
  9. // How to use lists
  10.  
  11. // You can add items to a list, or remove items, a list is treated like a collection of items. ( Items can be ints, strings, etc.)
  12.  
  13. // For example:
  14.  
  15. list.Add(7);     // I've added the number 7 as a list.
  16. list.Add(25);    // Now I've added the number 25 as a new list.
  17. list.Remove(7);  // Now I've removed the list that contained '7'
  18.  
  19. // There are many things you can do with lists, such as count the number of items in the list
  20.  
  21. Console.WriteLine(list.Count);   // Console is the Output window, where you can make the program show results.
  22.                                  // You use Console.WriteLine() to make the program write text to Output.
  23.                                  // Count is a function that counts the total number of items in a collection.
  24. Output:
  25. 3                                // This is the value you would receive in Output
  26.  
  27.  
  28. // You can use classes to get multiple values and set them as one object
  29.  
  30. class numset
  31. {
  32.    public int one { get; set; }
  33.    public int two { get; set; }
  34.    public int three { get; set; }
  35. }
  36.  
  37. List<numset> newlist = new List<numset>();
  38.  
  39. newlist.Add(new numset{ 1, 2, 3 }; // Add three values as one list using a class struct
  40.  
  41.  
  42. // There are a lot of uses for lists, and arrays (which I might write a pastebin on), but I'm at school so lol
  43. // Hope you understood something about lists :D
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement