C# 系统数组';不包含';计数';
在我的C#项目中,我得到了这样一个错误:count的定义不包含C# 系统数组';不包含';计数';,c#,asp.net,C#,Asp.net,在我的C#项目中,我得到了这样一个错误:count的定义不包含System.Array protected void Page_Prerender(object sender, EventArgs e) { FileInfo[] fileInfo; string UpFolder = Server.MapPath("~/data/images/"); DirectoryInfo dir = new DirectoryInfo(UpFolder); fileInfo
System.Array
protected void Page_Prerender(object sender, EventArgs e)
{
FileInfo[] fileInfo;
string UpFolder = Server.MapPath("~/data/images/");
DirectoryInfo dir = new DirectoryInfo(UpFolder);
fileInfo = dir.GetFiles();
// here i am getting error
int TotalImages = fileInfo.Count();
for (int count = 0; count < TotalImages; count++)
{
Image image = new Image();
image.ImageUrl = "~/data/images/" + fileInfo[count].ToString();
image.ID = count.ToString();
DataListImage.Controls.Add(image);
}
DataListImage.DataSource = dir.GetFiles();
DataListImage.DataBind();
string UpFolder1 = Server.MapPath("~/data/thumbnails/");
DirectoryInfo dir1 = new DirectoryInfo(UpFolder1);
DataListthumbnails.DataSource = dir1.GetFiles();
DataListthumbnails.DataBind();
}
受保护的无效页面\u预呈现(对象发送方,事件参数e)
{
FileInfo[]FileInfo;
字符串UpFolder=Server.MapPath(“~/data/images/”);
DirectoryInfo dir=新的DirectoryInfo(UpFolder);
fileInfo=dir.GetFiles();
//这里我得到了一个错误
int TotalImages=fileInfo.Count();
对于(int count=0;count
您不需要计数
,而是可以使用长度
和数组来获取计数
由于您缺少使用System.Linq的,因此会出现错误代码>
要获取TotalImages
,您可以使用
int TotalImages = fileInfo.Length;
虽然由于类型是数组,因此不需要使用Count()
,但该错误是由于未“使用”正确的命名空间造成的
是System.LINQ
命名空间中的LINQ扩展方法。因此,可通过以下方式提供:
using System.Linq;
因为数组实现了IEnumerable
,所以当它们可用时,它们可以使用任何这样的方法。酷,我喜欢这种情况:)我已经在使用System.Linq了,但为什么我不能在这里使用count???因为在我代表count images调整图像大小时,count和length之间存在一些差异。。尽可能多的图像大小,它将被优化accordingly@SiddiqBaig,Count
将返回数组中元素的总数,与lenght相同,它与图像大小无关。有关长度与计数的信息,请参见。