Guest User

Untitled

a guest
Nov 16th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApp2
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. Dictionary<string, int> inventory = new Dictionary<string, int>();
  14. inventory.Add("apple", 3);
  15. inventory.Add("orange", 5);
  16. inventory.Add("banana", 2);
  17.  
  18. foreach (KeyValuePair<string, int> entry in inventory)
  19. {
  20. Console.WriteLine(entry);
  21. }
  22. string firstName = "Michael";
  23. string lastName = "Gallego";
  24. int age = 22;
  25.  
  26. string phrase = String.Format("{0} {1} is the age of {2}", firstName, lastName, age);
  27. Console.WriteLine(phrase);
  28.  
  29. for (int i = 0; i < 10; i++)
  30. {
  31. if (i % 2 != 0)
  32. {
  33. Console.WriteLine(i);
  34. }
  35. }
  36. Console.WriteLine(Division(5, 2));
  37.  
  38. AnotherClass car1 = new AnotherClass(4, 2004, true);
  39. AnotherClass car2 = new AnotherClass(3, 2007, false);
  40. AnotherClass car3 = new AnotherClass(2, 2013, true);
  41.  
  42. List<AnotherClass> cars = new List<AnotherClass>();
  43. cars.Add(car1);
  44. cars.Add(car2);
  45. cars.Add(car3);
  46.  
  47. foreach (AnotherClass car in cars)
  48. {
  49. Console.WriteLine(car);
  50. }
  51.  
  52. Console.ReadKey();
  53. }
  54.  
  55.  
  56. public static float Division(int x, int y)
  57. {
  58. float divisionNumber = 0;
  59. divisionNumber = (float) x / (float) y;
  60. return divisionNumber;
  61. }
  62. }
  63.  
  64. class AnotherClass
  65. {
  66. int numTires;
  67. int year;
  68. bool runs;
  69.  
  70. public AnotherClass(int numTires, int year, bool runs)
  71. {
  72. this.numTires = numTires;
  73. this.year = year;
  74. this.runs = runs;
  75. }
  76.  
  77. public override string ToString()
  78. {
  79. if (runs)
  80. {
  81. return String.Format("This car runs, has {0} number of tires, and the year of the model is {1}", numTires, year);
  82. } else
  83. {
  84. return String.Format("The car does not run, but has {0} number of tires, and the year of the model is {1}", this.numTires, this.year);
  85. }
  86. }
  87.  
  88. }
  89. }
Add Comment
Please, Sign In to add comment