Why generic list assignment can't be ByVal
Posted on 2011-03-07
I'm just curious why in the following function (for System.Collections.Generic.List), the ByVal keyword doesn't appear to be followed:
Private Function GetListByVal(ByVal Input As List(Of Integer)) As List(Of Integer)
If I set another List object equal to this function and then sort it, the original list that I fed in also gets sorted. Therefore, it appears that "ByVal" is being ignored.
I understand that if I set one List object equal to another, then it will really be just a reference to the first one, so that sorting on one variable affects both. But even if I try to force .NET to duplicate the list, it still apparently maintains only one list with two references to it.