我正在尝试用属性名称和值填充列表,到目前为止,这是我的代码...
public class DirPropeties {
public string Name { get; set; }
public string Path { get; set; }
public string HiddenStatus { get; set; }
}
public static List<string> GetDirAttributes(string path, bool IsHidden = true)
{
List<DirPropeties> FolderArrayList = new List<DirPropeties>();
DirectoryInfo di = new DirectoryInfo(path);
DirectoryInfo[] subdirectories = di.GetDirectories();
foreach (DirectoryInfo dir in subdirectories)
{
if (IsHidden)
{
//FolderArrayList.Add(dir.Name);
FolderArrayList.Add(new DirPropeties { Name = dir.Name });
}
else if ((dir.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden)
{
FolderArrayList.Add(new DirPropeties { Name = dir.Name });
}
};
return FolderArrayList;
}
我这样称呼它。...
List<string> DirectoryArrayList = new List<string>();
DirectoryArrayList = BaseDirectory.GetDirAttributes(FileDetailsViewModel.FolderPath, FileDetailsViewModel.AllowHidden);
而且我正尝试像这样访问属性...
if (folderIndex >= DirectoryArrayList.Count) { break; }
var folder = DirectoryArrayList[folderIndex];
var label = new Label()
{
Text = folder.Name,
FontSize = 20,
VerticalTextAlignment = TextAlignment.Center,
HorizontalTextAlignment = TextAlignment.Center
};
我在返回FolderArrayList时遇到以下错误...
无法将类型'System.Collections.Generic.List'隐式转换为'System.Collections.Generic.List'
并且在文件夹上。名称我收到以下错误...
'字符串'不包含'名称'的定义]]
任何人都可以帮助我指导我解决这个问题吗?
我正在尝试用属性名称和值填充列表,到目前为止,这是我的代码...公共类DirPropeties {public string Name {get;组; }公用字符串Path {get;组; } ...
此代码中的任何地方都不需要使用List<string>
。更改