DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Mon, 30 Jul 2007 06:26:57 -0700,    posted on: microsoft.public.dotnet.framework.aspnet        back       

Thread Index
  1    Larry Bud
          2    Omar Abid
          3    Göran Andersson
          4    Larry Bud
                 5    Göran Andersson


Finding Dupe in a List   
I have a function which return a List, and I'm trying to add users to
it from 3 different roles, but I don't want duplicate user names.  The
"Contains" ALWAYS is returning FALSE, so I'm not finding the dupe.
Here's the code:

Dim datalist As New List(Of TroubleTicketUser)
Dim str As String
Dim theroles(2) As String, therole As String

theroles(0) = "IT User"
theroles(1) = "IT Admin"
theroles(2) = "Customer Service Rep"

For Each therole In theroles
	For Each str In Roles.GetUsersInRole(therole)
		Dim tt As New TroubleTicketUser(str)
		If Not datalist.Contains(tt) Then datalist.Add(tt)
	Next
Next

datalist.Sort()

Return datalist

---------------------
Why doesn't the Contains work?
Date:Mon, 30 Jul 2007 06:26:57 -0700   Author:  

Re: Finding Dupe in a List   
On 30 juil, 15:26, Larry Bud  wrote:

> I have a function which return a List, and I'm trying to add users to
> it from 3 different roles, but I don't want duplicate user names.  The
> "Contains" ALWAYS is returning FALSE, so I'm not finding the dupe.
> Here's the code:
>
> Dim datalist As New List(Of TroubleTicketUser)
> Dim str As String
> Dim theroles(2) As String, therole As String
>
> theroles(0) = "IT User"
> theroles(1) = "IT Admin"
> theroles(2) = "Customer Service Rep"
>
> For Each therole In theroles
>         For Each str In Roles.GetUsersInRole(therole)
>                 Dim tt As New TroubleTicketUser(str)
>                 If Not datalist.Contains(tt) Then datalist.Add(tt)
>         Next
> Next
>
> datalist.Sort()
>
> Return datalist
>
> ---------------------
> Why doesn't the Contains work?


Hi,
Check out this link : http://expressdotnet.freehostia.com
Omar Abid
Date:Mon, 30 Jul 2007 08:41:01 -0700   Author:  

Re: Finding Dupe in a List   
Larry Bud wrote:

> I have a function which return a List, and I'm trying to add users to
> it from 3 different roles, but I don't want duplicate user names.  The
> "Contains" ALWAYS is returning FALSE, so I'm not finding the dupe.
> Here's the code:
> 
> Dim datalist As New List(Of TroubleTicketUser)
> Dim str As String
> Dim theroles(2) As String, therole As String
> 
> theroles(0) = "IT User"
> theroles(1) = "IT Admin"
> theroles(2) = "Customer Service Rep"
> 
> For Each therole In theroles
> 	For Each str In Roles.GetUsersInRole(therole)
> 		Dim tt As New TroubleTicketUser(str)
> 		If Not datalist.Contains(tt) Then datalist.Add(tt)
> 	Next
> Next
> 
> datalist.Sort()
> 
> Return datalist
> 
> ---------------------
> Why doesn't the Contains work?
> 


The Contains method works just fine, it just doesn't work the way that 
you expected it to work.

The Contains method, when used on a List of reference types, checks if a 
reference to the object exists in the list. As you create a new instance 
of the TroubleTicketUser class, it's not the same object as the one that 
exists in the list, eventhough they contain the same data.

What you want to do is to use a Dictionary(Of String, TroubleTicketUser) 
where you use the user name as key.

-- 
Gran Andersson
_____
http://www.guffa.com
Date:Tue, 31 Jul 2007 11:56:00 +0200   Author:  

Re: Finding Dupe in a List   
On Jul 31, 5:56 am, Göran Andersson  wrote:

> Larry Bud wrote:
> > I have a function which return a List, and I'm trying to add users to
> > it from 3 different roles, but I don't want duplicate user names.  The
> > "Contains" ALWAYS is returning FALSE, so I'm not finding the dupe.
> > Here's the code:
>
> > Dim datalist As New List(Of TroubleTicketUser)
> > Dim str As String
> > Dim theroles(2) As String, therole As String
>
> > theroles(0) = "IT User"
> > theroles(1) = "IT Admin"
> > theroles(2) = "Customer Service Rep"
>
> > For Each therole In theroles
> >    For Each str In Roles.GetUsersInRole(therole)
> >            Dim tt As New TroubleTicketUser(str)
> >            If Not datalist.Contains(tt) Then datalist.Add(tt)
> >    Next
> > Next
>
> > datalist.Sort()
>
> > Return datalist
>
> > ---------------------
> > Why doesn't the Contains work?
>
> The Contains method works just fine, it just doesn't work the way that
> you expected it to work.
>
> The Contains method, when used on a List of reference types, checks if a
> reference to the object exists in the list. As you create a new instance
> of the TroubleTicketUser class, it's not the same object as the one that
> exists in the list, eventhough they contain the same data.
>
> What you want to do is to use a Dictionary(Of String, TroubleTicketUser)
> where you use the user name as key.


Ok, I get it.  However, from what I see, I can't sort a Dictionary.
Date:Tue, 31 Jul 2007 06:10:46 -0700   Author:  

Re: Finding Dupe in a List   
Larry Bud wrote:

> On Jul 31, 5:56 am, Gran Andersson  wrote:
>> Larry Bud wrote:
>>> I have a function which return a List, and I'm trying to add users to
>>> it from 3 different roles, but I don't want duplicate user names.  The
>>> "Contains" ALWAYS is returning FALSE, so I'm not finding the dupe.
>>> Here's the code:
>>> Dim datalist As New List(Of TroubleTicketUser)
>>> Dim str As String
>>> Dim theroles(2) As String, therole As String
>>> theroles(0) = "IT User"
>>> theroles(1) = "IT Admin"
>>> theroles(2) = "Customer Service Rep"
>>> For Each therole In theroles
>>>    For Each str In Roles.GetUsersInRole(therole)
>>>            Dim tt As New TroubleTicketUser(str)
>>>            If Not datalist.Contains(tt) Then datalist.Add(tt)
>>>    Next
>>> Next
>>> datalist.Sort()
>>> Return datalist
>>> ---------------------
>>> Why doesn't the Contains work?
>> The Contains method works just fine, it just doesn't work the way that
>> you expected it to work.
>>
>> The Contains method, when used on a List of reference types, checks if a
>> reference to the object exists in the list. As you create a new instance
>> of the TroubleTicketUser class, it's not the same object as the one that
>> exists in the list, eventhough they contain the same data.
>>
>> What you want to do is to use a Dictionary(Of String, TroubleTicketUser)
>> where you use the user name as key.
> 
> Ok, I get it.  However, from what I see, I can't sort a Dictionary.


That is correct. You have to use an Array, a List or a SortedList for 
that (or perhaps there are some more collections that can be sorted).

If you use a SortedList for example, you just have to loop through the 
Values of the dictionary and add them to the list.

-- 
Gran Andersson
_____
http://www.guffa.com
Date:Tue, 31 Jul 2007 22:36:48 +0200   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us