Destroy Variables
-
Dear friends, How can I destroy a variable in ASP.Net(C#). If anybody knows, please answer Regards Shivan
Shivanandan C V
-
Dear friends, How can I destroy a variable in ASP.Net(C#). If anybody knows, please answer Regards Shivan
Shivanandan C V
Assign null value to the variable .
int i ;
i=10;
i=null ; //destroy variable -
Dear friends, How can I destroy a variable in ASP.Net(C#). If anybody knows, please answer Regards Shivan
Shivanandan C V
i think variables are destroy after there scope is complete.... function () { var a; }---->here. why you need to destroy it??
umerumerumer
-
Dear friends, How can I destroy a variable in ASP.Net(C#). If anybody knows, please answer Regards Shivan
Shivanandan C V
Why you want this.Actually for any value type variable you does need to care because thaey are allocated n stack so they will be according to the scope of that variable. For reference type vaiable also ,the garbage collector take care of all this,you can also call garbage collector by your own but it is not advisable as per Microsoft.You can do one thing,if reference variablle if you don't need any more ,you can assign null it to you,it'll help gc.
Cheers!! Brij
-
i think variables are destroy after there scope is complete.... function () { var a; }---->here. why you need to destroy it??
umerumerumer
I am using dataTable to temporarily display data in GridView.So in my function I wrote code for adding fields and records. Then while running it for the second time, it displays error that column name already exists. So I think that the datatable is not getting cleared while stopping the program.
Shivanandan C V
-
Assign null value to the variable .
int i ;
i=10;
i=null ; //destroy variableNishant Singh wrote:
int i ; i=10; i=null ; //destroy variable
Wrong. This will not compile.
int
can't haveNULL
value.Navaneeth How to use google | Ask smart questions
-
Why you want this.Actually for any value type variable you does need to care because thaey are allocated n stack so they will be according to the scope of that variable. For reference type vaiable also ,the garbage collector take care of all this,you can also call garbage collector by your own but it is not advisable as per Microsoft.You can do one thing,if reference variablle if you don't need any more ,you can assign null it to you,it'll help gc.
Cheers!! Brij
Brij wrote:
if reference variablle if you don't need any more ,you can assign null it to you,it'll help gc.
No.
Navaneeth How to use google | Ask smart questions
-
I am using dataTable to temporarily display data in GridView.So in my function I wrote code for adding fields and records. Then while running it for the second time, it displays error that column name already exists. So I think that the datatable is not getting cleared while stopping the program.
Shivanandan C V
How this data table object is declared? Looks like you have incorrectly declared the data table.
Navaneeth How to use google | Ask smart questions
-
How this data table object is declared? Looks like you have incorrectly declared the data table.
Navaneeth How to use google | Ask smart questions
I have declared it as static DataTable dtMainTask = new DataTable();
Shivanandan C V
-
I have declared it as static DataTable dtMainTask = new DataTable();
Shivanandan C V
Shivan Nandan wrote:
static
This is the problem. Do you know what is the scope for a static variable? It lives until the application domain unloads. BTW, is there any specific reason for declaring it as static?
Navaneeth How to use google | Ask smart questions
-
Shivan Nandan wrote:
static
This is the problem. Do you know what is the scope for a static variable? It lives until the application domain unloads. BTW, is there any specific reason for declaring it as static?
Navaneeth How to use google | Ask smart questions
If I didnt declare it as static, then its value becomes empty in another function. ie, I declared it outside all the function , In Page_PreInit - declared the fields, In btnAdd_Click - wrote function to add rows Therefor if I didnt declare it as static then the fields are not accessible in btnAdd_Click function.
Shivanandan C V
-
i think variables are destroy after there scope is complete.... function () { var a; }---->here. why you need to destroy it??
umerumerumer
The variables are automatically destroyed once they are out of there scope. If u are talking abt object.Let the asp.net garbage collector handle it for u.