473,386 Members | 1,793 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

VB.Net-Winform: Unable to pass IList by value

2
At the risk of sounding like one of the usual morons who claim everything that goes wrong in their code is a bug - I am nearly convinced the following situation is a bug in VB.NET (and if its not it should be better documented)

I have written a simple function to find the difference between 2 lists (list1 - list2)

Expand|Select|Wrap|Line Numbers
  1. Public Shared Function ListDifference(ByVal list1 As IList, ByVal list2 As IList) As IList
  2.  
  3.         For list2index As Integer = 0 To list2.Count - 1
  4.             If (list1.Contains(list2(list2index))) Then
  5.                 list1.Remove(list2(list2index))
  6.             End If
  7.         Next
  8.  
  9.         Return list1
  10.  
  11.     End Function
  12.  
I call it with this line:

Expand|Select|Wrap|Line Numbers
  1.  Dim lstAvailableGroups As IList = Resources.ListDifference(_groupList, _currentUser.Groups)
  2.  
Before executing the function

_groupList contains:
Administrators
Payment Department
Management
HR Department
_currentUser.Groups contains:
Administrators
After executing the function

_groupList contains:
Payment Department
Management
HR Department
_currentUser.Groups contains:
Administrators
I am passing both lists by value. How is the function changing _groupList? Any help much appreciated.
May 18 '07 #1
1 1880
wdrone
2
After reading more and more and more MSDN docs. I think i have discovered the problem.

According to this documentation
http://msdn2.microsoft.com/en-us/lib...h4(VS.80).aspx

"Reference type (contains a pointer to a class or structure instance)"
"When passed ByVal the procedure cannot change the variable but can change members of the instance to which it points."

Therefore if an IList is a reference type (which i'm sure it is) its items can be modified even if the IList is passed byVal.

So in my problem and all other situations like this the ByVal implementation only makes a shallow copy of the List and both the original and the copy still reference the same items. Yuck. I'm curious if you have a custom class that contains a collection of items and you pass it to a function byVal if the same situation exists.

If any experts want to chime in on this great, otherwise i consider this to be a closed issue.

It's been great chatting with my self ;)
May 18 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: lawrence | last post by:
I haven't been able to reach www.php.net for days. Most of the rest of the web is working for me, though I've bad trouble reaching any English sites. Anyone else having trouble?
0
by: Georgeo Pulikkathara[MS] | last post by:
ASP.NET Webcast Week - January 19 - 23, 2004 Learn about ASP.NET from the experts! These free webcasts are live and interactive. Live code demos and attendees asking in depth engaging questions are...
1
by: Novice | last post by:
Hi all, I am a C++ and Java developer with over 3 years of industry experience. I've written low level C++ code, in addition to web clients that use web services. I've just recently installed the...
9
by: gulu man | last post by:
Hi, What is the substitute for COM objects in .NET? How can I create something similar to com in .net? Is it still possible? Thank you
20
by: Olav.NET | last post by:
I am a .NET/C++ developer who is supposed to do some work with Access. I do not know much about it except for the DB part. Questions: *1* I am looking for INTENSIVE books to get quickly up to...
0
by: Georgeo Pulikkathara[MS] | last post by:
ASP.NET Webcast Week - January 19 - 23, 2004 Learn about ASP.NET from the experts! These free webcasts are live and interactive. Live code demos and attendees asking in depth engaging questions are...
9
by: Bob | last post by:
Is ASP.NET 1.1 available on the 64 bit extended version of Windows 2003 Server? When I install VS.NET 2003 I then get Service Unavailable from IIS when navigating to the main under construction...
132
by: Kevin Spencer | last post by:
About 2 years ago, and as recently as perhaps 1 year ago, I can recall seeing many posts about what language to use with ASP.Net. The consensus was that employers paid more for C# programmers, and...
2
by: Juan T. Llibre | last post by:
Welcome to the ASP.NET FAQ. Thank you for reading this FAQ! Use it to improve your online experience. The Microsoft Public Newsgroups allow users of Microsoft products to exchange technical ...
0
by: Juan T. Llibre | last post by:
Welcome to the ASP.NET FAQ. The online version of this FAQ is at http://asp.net.do/faq/ Thank you for reading this FAQ! Use it to improve your online experience. The Microsoft Public...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.