-1

Error:

'FileProtect.FileUrl._url' is inaccessible due to its protection level

Getting the above error for some reason, all i'm trying to do is put a collection of objects in a List...

public void load()
        {
            string test = "C:\\Users\\Martyn Ball\\Desktop\\";
            string[] filePaths = Directory.GetFiles(@test);

            foreach (string tmp in filePaths)
            {
                //Add file url to custom object
                FileUrl fileInfo = new FileUrl();
                fileInfo.url = tmp;

                //Is it file/folder

                //Add to list
                currentFolder.Add(fileInfo);
            }
        }

Here is the class:

public class FileUrl
    {
        string url { get; set; }
        int filefolder { get; set; }
    }
Martyn Ball
  • 4,311
  • 6
  • 45
  • 112

2 Answers2

1

Class members are private by default, so your class is defined like this:

public class FileUrl
{
    private string url { get; set; }
    private int filefolder { get; set; }
}

Thus, those properties can't be accessed from outside the object, which you try to do here:

FileUrl fileInfo = new FileUrl();
fileInfo.url = tmp;

You can make the property public instead:

public string url { get; set; }
David
  • 188,958
  • 33
  • 188
  • 262
0

You should make url property public if you want to access it outside of your class.

Selman Genç
  • 97,365
  • 13
  • 115
  • 182