Sponsored Ad

Tuesday, April 5, 2011

Inconsistent accessibility: property type 'MyApp.class_type' is less accessible than property 'MyApp.operator_error_class.my_prop' – C# Error

When you try to access a class from another class which have higher accessibility.

using System;

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

        public class_type my_prop
        {
            get
            {
                return new class_type();
            }
        }

    }
    class class_type
    {
    }
}

How to fix above Error:

add public access in front of class_type class.

using System;

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

        public class_type my_prop
        {
            get
            {
                return new class_type();
            }
        }

    }
    public class class_type
    {
    }
}

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();
        }      
    }
}

How to Fix C# Error - Identifier too long

This error you will get when you try to declare a variable of length more than 512 chars. The below code will produce a compile time error: Identifier too long

using System;

namespace MyApp
{
    class too_long_class
    {
        public static void Main(string[] args)
        {
            int intsssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss = 0;
            Console.WriteLine();
            Console.Read();
        }      
    }
}

To fix above error just reduce the number of char in variable name less than 512.

Sponsored Ad

Development Updates