3 回答

TA貢獻1829條經(jīng)驗 獲得超7個贊
這將是正確的實現(xiàn),雖然我沒有看到您需要在您發(fā)布的代碼中處置任何內(nèi)容。您只需要在以下時間實施IDisposable:
您有非托管資源
你正在堅持引用本身就是一次性的東西。
您發(fā)布的代碼中沒有任何內(nèi)容需要處理。
public class User : IDisposable
{
public int id { get; protected set; }
public string name { get; protected set; }
public string pass { get; protected set; }
public User(int userID)
{
id = userID;
}
public User(string Username, string Password)
{
name = Username;
pass = Password;
}
// Other functions go here...
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
// free managed resources
}
// free native resources if there are any.
}
}
- 3 回答
- 0 關(guān)注
- 858 瀏覽
添加回答
舉報