MembershipCollection question

  • Thread starter Thread starter GaryDean
  • Start date Start date
G

GaryDean

The static MembershipCollection class appears to work different than other
collection classes...

MembershipUserCollection myUsers = new MembershipUserCollection();
myUsers = Membership.GetAllUsers();
MembershipUser myMember = myUsers.Item[0]; <---- no Item property

This collection has no Item property. Why? The only way I can reference an
individual member of this collection is to specify the string value of the
key field (in this case username).

Thanks,
Gary
 
It is designed to be used with the user name, so leaving it out is not as
strange as it might seem.

If you absolutely need an indexer, consider creating a custom provider and
have it call most of the underlying methods except add a publicly exposed
indexer.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com
Co-author: Microsoft Expression Web Bible (upcoming)

************************************************
Think outside the box!
************************************************
 
Hi Gary,

As Gregory has mentioned here, since MembershipUser instances are mainly
identified through their username, and index based locator doesn't help
much in the collection, so the MembershipuserCollection class doesn't
implement the index based accessor. However, if you do need index based
access to a list of MembershipUser objects, you can use the
"MembershipUserCollection.CopyTo" method to copy the list into a
MembershipUser[] array and access them through index based pattern.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top