Advertisement
Guest User

Untitled

a guest
May 24th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. public int ReturnCar(string vehicleRego)
  2. {
  3. int cuscar = 0;
  4. List<string> mylist = new List<string> { };
  5. List<string> separatelist1 = new List<string> { };
  6. string s = "";
  7. if(rentals.ContainsKey(vehicleRego))
  8. {
  9. foreach (KeyValuePair<string, int> car in rentals)
  10. {
  11. s = car.Key + "," + car.Value.ToString();
  12. mylist.Add(s);
  13. }
  14. for (int i = 0; i < mylist.Count(); i++)
  15. {
  16. if (mylist[i].Split(',').ToList().Contains(vehicleRego))
  17. {
  18. cuscar = int.Parse(mylist[i].Split(',').ToList()[1]);
  19. mylist.Remove(mylist[i]);
  20. i--;
  21. };
  22. };
  23. rentals.Clear();
  24. for (int a = 0; a < mylist.Count(); a++)
  25. {
  26. separatelist1 = mylist[a].Split(',').ToList();
  27. if (int.TryParse(separatelist1[1], out myvalue) == true)
  28. {
  29. mykey = separatelist1[0];
  30. myvalue = int.Parse(separatelist1[1]);
  31. rentals.Add(mykey, myvalue);
  32. separatelist1.Clear();
  33. }
  34. }
  35. }
  36. if (!rentals.ContainsKey(vehicleRego) && cuscar == 0)
  37. {
  38. cuscar = -1;
  39. };
  40. return cuscar;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement