I'm studying c# from Linkedin Learning, and in a lesson, the professor code worked great in the video, but the exact same file doesn't work for me, returning the error:
Input string was not in a correct format.
This is the code that doesnt work:
using System; 
using System.Globalization;
namespace Parsing {
    class Program
    {
        static void Main(string[] args)
        {
            string numStr = "2.00";
            int targetNum=0;
            try {
                targetNum = int.Parse(numStr, NumberStyles.Float);
                Console.WriteLine(targetNum);
            }
            catch(Exception e) {
                Console.Write(e.Message);
                
            }
         
            bool succeeded = false;
            
            if (succeeded) {
                Console.WriteLine($"{targetNum}");
            }
        }
    } 
}
This, however, does work:
using System; 
using System.Globalization;
namespace Parsing {
    class Program
    {
        static void Main(string[] args)
        {
            string numStr = "2";
            int targetNum=0;
            try {
                targetNum = int.Parse(numStr, NumberStyles.Float);
                Console.WriteLine(targetNum);
            }
            catch(Exception e) {
                Console.Write(e.Message);
                
            }
         
            bool succeeded = false;
            
            if (succeeded) {
                Console.WriteLine($"{targetNum}");
            }
        }
    } 
}
Anyone have a light to shine on why the other code doesn't work?


