问题描述
嗨朋友们,
当我对修改日期进行c#编码时出错。我已经用2天来解决问题,但仍然有错误。有显示5错误,这是;
1.System.Collections.Generic.IEnumerable< string>'不包含'Length'的定义,也没有扩展名方法'Length'接受类型'System.Collections.Generic.IEnumerable< string>'的第一个参数可以找到(你是否缺少using指令或汇编引用?)
2.System.Collections.Generic.IEnumerable< string>'不包含'Length'的定义,也没有扩展方法'Length'接受类型'System.Collections.Generic.IEnumerable< string>类型的第一个参数'可以找到(你错过了使用指令或程序集引用吗?)
3.无法使用[]将索引应用于'System.Collections类型的表达式.Generic.IEnumerable< string>
4.最佳重载方法匹配'System.Array.Sort< System.DateTime>(System.DateTime [],System .Comparison< ; System.DateTime>)'有一些无效的参数
5.Argument 2:无法从'System.Collections.Generic.IEnumerable< string>'转换为'系统。比较< System.DateTime>'
代码;
Hi Friends,
I have error when i doing c# coding for the date modified. I m already use 2 days for settle the problem, but still have error. There are shows 5 error, which is;
1.System.Collections.Generic.IEnumerable<string>' does not contain a definition for 'Length' and no extension method 'Length' accepting a first argument of type 'System.Collections.Generic.IEnumerable<string>' could be found (are you missing a using directive or an assembly reference?)
2.System.Collections.Generic.IEnumerable<string>' does not contain a definition for 'Length' and no extension method 'Length' accepting a first argument of type 'System.Collections.Generic.IEnumerable<string>' could be found (are you missing a using directive or an assembly reference?)
3.Cannot apply indexing with [] to an expression of type 'System.Collections.Generic.IEnumerable<string>
4.The best overloaded method match for 'System.Array.Sort<System.DateTime>(System.DateTime[], System.Comparison<System.DateTime>)' has some invalid arguments
5.Argument 2: cannot convert from 'System.Collections.Generic.IEnumerable<string>' to 'System.Comparison<System.DateTime>'
Code;
protected void Button1_Click(object sender, EventArgs e)
{
ListBox1.Items.Clear();
string search = TextBox1.Text; // here type the folder name
if (search != "")
{
string[] ext = new string[] { ".jpg", ".gif", ".png",".PNG", ".GIF", ".JPG", ".bmp", ".BMP" };
var directory = new DirectoryInfo(@"\\192.168.0.56\Test\Report\");
var files = Directory.GetFiles(directory + search, "*.*", SearchOption.AllDirectories).Where(s => ext.Any(n => s.EndsWith(n)));
DateTime[] creationtime = new DateTime[files.Length]; //**Error on "Length"
for (int i = 0; i < files.Length; i++) //**Error on "Length"
creationtime[i] = new FileInfo(files[i]).CreationTime; //**Error on "files[i]"
Array.Sort(creationtime, files); //**Error all line
foreach (string file in files)
{
ListBox1.Items.Add(new ListItem(Path.GetFileName(file), file)); // listed all files in the search folder
}
{
search = "";
}
}
else
{
Response.Write("<script>alert('Please Enter Search Keyword');</script>");
}
}
请帮助我......我真的需要帮助...给我任何建议避免错误......
Please help me...i m really need help...give me any suggestion to avoid the error...
推荐答案
protected void Button1_Click(object sender, EventArgs e)
{
ListBox1.Items.Clear();
string search = TextBox1.Text; // here type the folder name
if (search != "")
{
string[] ext = new string[] { ".jpg", ".gif", ".png", ".PNG", ".GIF", ".JPG", ".bmp", ".BMP" };
var directory = new DirectoryInfo(@"\\192.168.0.56\Test\Report\");
var files = Directory.GetFiles(directory + search, "*.*", SearchOption.AllDirectories).Where(s => ext.Any(n => s.EndsWith(n)));
DateTime[] creationtime = new DateTime[files.Count()]; //**Solve Error on "Length"
for (int i = 0; i < files.Count(); i++) //**Solve Error on "Length"
creationtime[i] = new FileInfo(files.ElementAt(i)).CreationTime; //**Solve Error on "files[i]"
Array.Sort(creationtime, files.ToArray()); //**Solve Error all line
foreach (string file in files)
{
ListBox1.Items.Add(new ListItem(Path.GetFileName(file), file)); // listed all files in the search folder
}
{
search = "";
}
}
else
{
Response.Write("<script>alert('Please Enter Search Keyword');</script>");
}
}
这篇关于根据修改日期列出文件时出错。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!