Categories

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

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:

C#

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

namespaceAnon

{

publicclasslogFormat

{

stringsource{get;set;}

stringsubstitute{get;set;}

}

publicList<logFormat>logList{get;set;}

publicForm1()

{

InitializeComponent();

stringtext=String.Empty;

pathFileName=String.Empty;

logText=String.Empty;

...

logList=newList<logFormat>();

parsedText=parsedText.Replace(nm.Groups[0].ToString(),change);

//pathFileName = "c:\\CountDocsJobError.txt";

logList.Add(newlogFormat(){

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: