微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c# – System.Array’不包含’Count’的定义

在我的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 = 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();
}

解决方法

您不需要Count,而是可以使用Length with arrays来获取计数.

您正在使用System.Linq丢失错误;

要获得TotalImages,您可以使用

int TotalImages = fileInfo.Length;

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐