Sponsored Ad

Tuesday, April 5, 2011

How to Fix C# Error: Operator '+' cannot be applied to operand of type 'string'

You will get this C# error (Operator '+' cannot be applied to operand of type 'string') when you try to apply binary + operator with only single operand. To fix this error, you need to have + operator between the two strings.

using System;

namespace MyApp
{
    class operator_error_class
    {
        public static void Main(string[] args)
        {

            string s = + "my string";
            Console.Read();
        }      
    }
}

Working version above program:

using System;

namespace MyApp
{
    class operator_error_class
    {
        public static void Main(string[] args)
        {

            string s = "Its" + "my string";
            Console.Read();
        }      
    }
}

No comments:

Post a Comment

Sponsored Ad

Development Updates