If I nullify the value in the case of collection in the called function,it is not affecting in the calling method.It is still having the original values..Why the value is not null in the calling function..?
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Dipa AhujaPosted May 26, 2010, 7:47 AM
Jaish MathewsPosted May 26, 2010, 7:46 AM
What understood is that you are asking why ArrayList not null even after made it null in side another function. Actually it's null only, but you are not storing that value and seems like it's not null. Look below code and concentrate on bolded lines where I stored the latest version after nullified. Here I am getting null
private void Form1_Load(object sender, EventArgs e)
{
ArrayList arr = new ArrayList();
arr.Add(1);
arr = SomeMethod(arr);
}
public ArrayList SomeMethod(ArrayList arr)
{
arr = null;
return arr;
}
Dipankar SanaPosted May 26, 2010, 7:37 AM
But I just wanted to know why it was behaving like that when not adding ref.. ?
Dipa AhujaPosted May 26, 2010, 7:23 AM
Dipankar SanaPosted May 26, 2010, 7:20 AM
Why the null value is not reflecting whereas modifications are getting reflected ??
Dipa AhujaPosted May 26, 2010, 7:15 AM
Dipankar SanaPosted May 26, 2010, 6:54 AM
I have created one arraylist.
ArrayList arr=new ArrayList();
Arr.Add(1);
SomeMethod(Arr);
Public ArrayList SomeMethod(ArrayList Arrs)
{
Arrs.Add(2);
return Arrs;
}
In the above case the updated result is getting reflected in the variable Arr in calling method i.e now we are getting two items in Arr.
But if in SomeMethod function we nullify Arrs and return Arrs.its not getting updated with null value in calling function .Still it is having old value..i.e 1.
Dipa AhujaPosted May 26, 2010, 6:30 AM