TryParsing a string to an int? Help?

I am trying to TryParse a string to an int. Can someone help me with this and explain how it works the way that it does?

static int Cincinnati(int cowInventory) { int cowsSold;

 Console.Clear(); Console.WriteLine("You're now in Cincinnati"); Console.WriteLine(); Console.WriteLine("You current Cow Inventory is: {0}", cowInventory); Console.Write("How many cows did you sell?"); Console.WriteLine(); cowsSold = int.Parse(Console.ReadLine()); // We have to use a TryParse cowInventory = cowInventory - cowsSold; Console.WriteLine("New Cow Inventory: {0}", cowInventory) Console.WriteLine("Press any key to continue"); Console.ReadKey(); return cowInventory; 

by Androidguy10 via /r/csharp

Leave a Reply