Fixing error "'Namespace.className.source' is inaccessible due to its protection level" in C#




The reason of error  "'Namespace.className.source' is inaccessible due to its protection level" is that by default class variables "source" and "substitute" are protected and you don’t have access to them anywhere out of the class.

Here’s an example of code with this error:

namespace Anon
{

    public class logFormat
    {
        string source { get; set; }
        string substitute { get; set; }
    }

    public List<logFormat> logList { get; set;}

        public Form1()
        {

            InitializeComponent();
            string text = String.Empty;
            pathFileName = String.Empty;
            logText = String.Empty;
...

            logList = new List<logFormat>();
parsedText = parsedText.Replace(nm.Groups[0].ToString(), change);
            //pathFileName = "c:\\CountDocsJobError.txt";
                    logList.Add(new logFormat() {
                        source = nm.Groups[0].ToString(),
                        substitute = change
                    });


        }
}

 

To fix the error "'Anon.logFormat.source' is inaccessible due to its protection level"  you should make variables public:

    public class logFormat
    {
        public string source { get; set; }
        public string substitute { get; set; }
    }

 




No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment





MarkiMarta.com. Notes of web-specialist
Since 2009
18+