Questions tagged [keyedcollection]
23 questions
8
votes
8 answers
Keyed Collection in Python?
Is there any equivalent to KeyedCollection in Python, i.e. a set where the elements have (or dynamically generate) their own keys?
i.e. the goal here is to avoid storing the key in two places, and therefore dictionaries are less than ideal (hence…

user541686
- 205,094
- 128
- 528
- 886
3
votes
2 answers
What is the most efficient way to obtain the list of keys from a KeyedCollection?
I am looking for a way that is as efficient as the Keys property (of type KeyCollection) of a generic dictionary.
Using a Linq select statement would work, but it would iterate over the whole collection each time the keys are requested, while I…

Erwin Mayer
- 18,076
- 9
- 88
- 126
3
votes
5 answers
How do you sort a KeyedCollection?
Basically I've got a KeyedCollection, and I want to be able to sort the collection by the key (or preferably with a custom comparer).
If this isn't possible, can someone recommend another class where the key is embedded in the…

Migwell
- 18,631
- 21
- 91
- 160
3
votes
3 answers
Adding and retrieving from a KeyedCollection
I want to use a KeyedCollection to store a class against a string key value. I have the following code:
public class MyClass
{
public string Key;
public string Test;
}
public class MyCollection : KeyedCollection
{
…

Paul Michaels
- 16,185
- 43
- 146
- 269
3
votes
4 answers
How can I get a KeyedCollection to be read-only?
First let me explain why I'm using a KeyedCollection. I'm building a DLL and I have a list of items that I need to add to a collection and have them stay in the order I placed them but I also need to access them by both their index and by key (the…

AbeyMarquez
- 625
- 4
- 13
2
votes
5 answers
Fastest way to copy a KeyedCollection
I'm working on a C# object copy constructor, part of which involves copying the contents of a KeyedCollection into a new KeyedCollection. This is what I have implemented currently:
class MyKeyedCollection : KeyedCollection
{
…

Whatsit
- 10,227
- 11
- 42
- 41
2
votes
2 answers
KeyedCollection is a collection of what?
I want to create a method that would iterate through a keyed collection. I want to make sure that my method support iteration of any collection that extends the KeyedCollection>
Here's the method:
public void…

Boris
- 9,986
- 34
- 110
- 147
2
votes
1 answer
Is KeyedCollection meant only when Key determines the equality of the items in it?
I think this is a common problem we run into.
class Person
{
public string place;
public string name;
public Person(string place, string name)
{
this.place = place;
this.name = name;
}
public bool…

nawfal
- 70,104
- 56
- 326
- 368
2
votes
1 answer
The type or namespace name could not be found keyedcollection
I'm fairly new to C# so forgive me if this is a stupid question. I'm experiencing an error but I do not know how to resolve it. I'm using Visual Studio 2010.
This code line
public class GClass1 : KeyedCollection
Gives me the error…

user1839542
- 33
- 2
1
vote
1 answer
Trying to implement Serializble DIctionary from Keyedcollection, unable to add objects
Long story short, I needed a set of objects with dictionary-like functionality that can be serialized in order to save user data. The original dictionary was a Dictionary class that held an array of Item objects and the amounts of each object…

ChargerIIC
- 1,620
- 1
- 33
- 47
1
vote
1 answer
Protobuf-net KeyedCollection serialization
I need to serialize/deserialize a KeyedCollection with protobuf-net, can I just serialize a list?
If so, what is the most efficient way to convert-back the List to the KeyedCollection?
Here follows a sample code that shows the case:
public class…

ilCosmico
- 1,319
- 15
- 26
1
vote
1 answer
Serialize Keyedcollection which contains another keyedcollection
I recently started working with vb.net coming from vba.
For my planned application I wanted to create a KeyedCollection which stores another keyedcollection. The reason is I have a kind of database, where I want to be able to store for a varying…

Johannes
- 161
- 1
- 6
1
vote
1 answer
SortedList vs. KeyedCollection
I've been using SortedList(key,value) a lot lately, but I would like to know how it is different than KeyedCollection(key, value), except for the obvious sorting part.
For example, if I'm building a class that requires capabilities of retrieving…

Yevgeni Grinberg
- 359
- 5
- 19
0
votes
1 answer
Creating a LINQ expression to get the correct property at the bottom of a KeyedCollection
I'm having some issues refactoring and ordering a list.
I have a class called DomainCollection which inherits from KeyedCollection.
public class DomainCollection : KeyedCollection, IDomainCollection where T : class, IDomainObject
I…

Kyuzo
- 21
- 1
- 8
0
votes
2 answers
Why Sets are considered keyed collections in JavaScript?
I noticed that Sets are being classified as keyed collections, and according the definition is a:
collections of data which are ordered by a key
but aren't the Set keys the values indexes? I'm not sure why they aren't classified as indexed…

José Salgado
- 981
- 10
- 25