asp.net - Is that a correct way to use Dispose Method? -
Here I settled the method in aspx.cs, but I'm not sure how to deal with objects Is Obvisoly correctly I surf it from the net and used it in my code, can you please say that the object is removing in the right format.
This is my method aspx.cs
public list & lt; Cause field & gt; List (datatelle dt) {list & lt; Cause field & gt; Lst = new list & lt; Causefield & gt; (); Foreach (DataRow line in dt.rows) {Uses (due to reasons FacebookBook sign up its description = new reasonfield ()) {SignUpDetails.FirstName = line ["first name"]. ToString (); SignUpDetails.ListName = Line ["Last name"]. ToString (); SignUpDetails.Birthdate = Line ["Birthday"]. ToString (); SignUpDetails.Gender = Line ["Gender"]. ToString (); Lst.Add (SignUpDetails); SignUpDetails.Dispose (); }} Return List; } My class file:
Completion of public class reasons: IDisposable {public string first name {get; Set; } Public String LastName {get; Set; } Public String Birthday {Received; Set; } Public string gender {receipt; Set; } Private component component = new component (); Private boole dealt = false; Public Zero Extraction (Settlement (true); GC.SuppressFinalize (this);} Private Wide Disposing (see) Check that Dispos has already been called or not. If (! It is DISSPOZED) { // If the settlement is equal to the right, then manage all managed // and resolve unmanaged resources. If (settlement) {// Settlement managed resources component.Dispose ();}} Disposed = true;}}
using If the address automatically calls at the end of the block , then you should not call it yourself again. In addition, in general, Unless you are holding on to some external resources (locks, file handles, sockets, database connections, etc.) or unmanaged memory (and I suspect this is a case in case for you), you should finalize or The method should not be garbage collector, managed Mriti to take care of the free.
Comments
Post a Comment