示例#1
0
        static void Main(string[] args)
        {
            int value = Convert.ToInt32("42");

            Console.WriteLine("value = {0}", value);

            value = int.Parse("42");
            Console.WriteLine($"value = {value}");

            bool success = int.TryParse("42", out value);

            Console.WriteLine($"value = {success}");

            MyClass myClass = new MyClass(1, "First item");

            Console.WriteLine($"myClass = {myClass.GetType()} - {myClass.ToString()}");
            string myClassStr = Convert.ToString(myClass);

            Console.WriteLine($"myClassStr = {myClassStr.GetType()} - {myClassStr.ToString()}");

            var input    = "2 Second item";
            var myClass2 = MyClass.Parse(input);

            Console.WriteLine($"myClass2 = {myClass2}");

            Console.Write("Press a key to exit");
            Console.ReadKey();
        }
示例#2
0
        static void Main(string[] args)
        {
            int value = Convert.ToInt32("42");

            Console.WriteLine("value = {0}", value);

            value = int.Parse("42");
            Console.WriteLine("value = {0}", value);

            bool success = int.TryParse("42", out value);

            Console.WriteLine("value = {0}", success);

            MyClass myClass = new MyClass(1, "First item");

            Console.WriteLine("myClass = {0}", myClass);

            var input    = "2 Second item";
            var myClass2 = MyClass.Parse(input);

            Console.WriteLine("myClass2 = {0}", myClass2);

            Console.Write("Press a key to exit");
            Console.ReadKey();
        }