Sponsored Ad

Thursday, March 24, 2011

How to Fix Object must be of type String : ArgumentException in C#

This C# program will help you to catch C# ArgumentException. As you can see that the function accepting the object type while we are passing int type.

How to Fix Object must be of type String : ArgumentException in C#

using System;

namespace MyApp
{
    class ArgumentException_class
    {
        public static void Main(string[] args)
        {
            try
            {
                string strException = "C# ArgumentException Example";
                strException.CompareTo(123);        
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine("Exception: {0}", ex.Message);
            }
            Console.Read();
        }
    }
}

No comments:

Post a Comment

Sponsored Ad

Development Updates