在这里,我使用了 aspx.cs 中的 dispose 方法,但我不确定处理对象的方式是否以正确的方式完成。Obvisoly我从网上冲浪并在我的代码中使用它,你能说无论对象是否以正确的格式处理。
这是我在 aspx.cs 中的方法
public List<CausesField> list(DataTable dt)
{
List<CausesField> lst = new List<CausesField>();
foreach (DataRow row in dt.Rows)
{
using (CausesField SignUpDetails = new CausesField())
{
SignUpDetails.FirstName = row["FirstName"].ToString();
SignUpDetails.LastName = row["LastName"].ToString();
SignUpDetails.Birthdate = row["BirthDay"].ToString();
SignUpDetails.Gender = row["Gender"].ToString();
lst.Add(SignUpDetails);
SignUpDetails.Dispose();
}
}
return lst;
}
我的班级文件:
public class CausesField:IDisposable
{
public string FirstName { get; set; } public string LastName { get; set; }
public string Birthdate { get; set; } public string Gender { get; set; }
private Component component = new Component();
private bool disposed = false;
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
private void Dispose(bool disposing)
{
// Check to see if Dispose has already been called.
if (!this.disposed)
{
// If disposing equals true, dispose all managed
// and unmanaged resources.
if (disposing)
{
// Dispose managed resources.
component.Dispose();
}
}
disposed = true;
}
}