问题描述
我有一个* .swf文件的文件夹.我必须将fileInformation放入列表中.在下面,我创建了一个对象,当我添加到列表中时,它仅返回空详细信息.找到我做过薄雾的地方.在此帮助我
I have a Folder of *.swf files.i have to get the fileInformation in to List.Here in below i have created an object,when i am adding into the list it returns null details only.I coudn''t find where i have done the mistae.Help me in this
public List<Course> FileInfoSelected(string pathFolder)
{
List<Course> courses = new List<Course>();
string FilePath="C:\\magnil\\Gavas\\"+pathFolder;
DirectoryInfo dir = new DirectoryInfo(FilePath);
FileInfo[] filedetails = dir.GetFiles("*.swf");
foreach (FileInfo FI in filedetails)
{
courses.Add(new Course(FI.Name, FI.Length,FI.LastAccessTime));
}
return courses;
}
推荐答案
FileInfo[] filedetails = dir.GetFiles("*.swf");
通过放置调试点,确保获得文件详细信息.
By putting debug point make sure that you are getting filedetails.
courses.Add(new Course(FI.Name, FI.Length,FI.LastAccessTime));
为此,请确保您的Class Course
具有带有三个参数的constructor
,
并且您已经使用public property
作为这些参数,
为了可以访问它,并且正在constructer
内部初始化这些parameter
的值,这样它就不会获取NULL
值.
如果有帮助,请 投票 和 接受答案 .
For this make sure your Class Course
having constructor
with three args,
and also you have used public property
for those parameters,
So that it can be accessed and inside the constructer
you are initializing the value of those parameter
so that it doesn''t get NULL
values.
Please vote and Accept Answer if it Helped.
这篇关于将对象添加到列表中时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!