0

我正在从文件上传控件中获取字节数组并将它们保存在一个类对象中,但是我遇到了 stackoverflow 无限循环或递归之类的异常。

我的代码是:

public class UploadDetail
{`enter code here`
    //public bool IsReady { get; set; }
    public string FileSize { get; set; }
    //public int UploadedLength { get; set; }
    public string FileName { get; set; }
    public byte[] FileinBytes;


    public byte[] FileBytes
    {
        get
        {
            return FileBytes;
        }

        set
        {                
            FileBytes = value;
        }
    }

这是我设置对象值的gridview按钮事件:

 protected void gvUploadFiles_Clicked(object sender, GridViewCommandEventArgs e)
 {
     try
     {    
         if (e.CommandName == "doingUpload")
         {

             int index = Convert.ToInt32(e.CommandArgument);

             GridViewRow row = gvUploadFiles.Rows[index];

             if (gvUploadFiles.DataKeys[index]["FileName"] != null)
             {
                 currentUpload.FileName = gvUploadFiles.DataKeys[index]["FileName"].ToString();
             }

             if (gvUploadFiles.DataKeys[index]["FileSize"] != null)
             {
                 currentUpload.FileSize = gvUploadFiles.DataKeys[index]["FileSize"].ToString();
             }


             if (gvUploadFiles.DataKeys[index]["FileBytes"] == null)
             {
                 currentUpload.FileBytes=(byte[])gvUploadFiles.DataKeys[index]["UploadDetail.FileBytes()"];
                 //currentUpload.FileBytes(row.FindControl("fileBytes"));
             }
4

1 回答 1

1

您的 getter/setter 中有无限递归。

你想写它FileinBytes吗?

public byte[] FileBytes
{
    get
    {
        return FileinBytes;
    }

    set
    {
        FileinBytes = value;
    }
}

另一种方法是使用自动实现的属性:

public byte[] FileBytes { get; set; }
于 2012-09-06T07:51:58.203 回答