I have a confusion regarding passing list to a function in dart
here i have made two example to clear my query
in first example
when i passed a list to function and add some new values to list…it effect’s void main’s list. thats fine like passing byref
but in another example,
when i pass a list to function and applying him brand new list ..it does not affet void main’s list..why?
where should i get documentation regarding this…its long time i am confused in byval and byref while passing list or object
void update(List<String> list)
{
list.add('C');
}
void main()
{
List<String> names=['A','B'];
print('Before'+names.toString());
update(names);
print('after'+names.toString());
}
//Before[A, B] after[A, B, C] means updating void main's names
Program 2
void update(List<String> list)
{
List<String> newNames=['x','y'];
list=newNames;
}
void main()
{
List<String> names=['A','B'];
print('Before'+names.toString());
update(names);
print('after'+names.toString());
}
//Before[A, B] after[A, B] here not updating void main's names, and why?