A
A
Artem Ivantsov2015-04-17 09:44:58
Arrays
Artem Ivantsov, 2015-04-17 09:44:58

C# What is the best storage for my data array?

Hello. I have several data types of this kind.

public class SomeClass1
    {
        public Int32 SomeKeyValue;
        public Int32 SomeOtherValue1;
        public String SomeOtherValue2;
    }
    public class SomeClass2
    {
        public SomeEnum SomeKeyValue;
        public Int32 SomeOtherValue1;
        public String SomeOtherValue2;
    }

Earlier in the development process, I used a regular array with a LINQ lookup on a unique key field. Initially, an array was selected, since the number of elements is fixed and does not change during the program.
But then I needed to speed up the work and it was decided to look at other types of storages.
I really liked the Dictionary, which uses a key field from the class as a key. But in this case, I need to remove the key field from the class and store it in the dictionary key. Of course, you can not delete it, but it will be duplicated.
That's the question itself, if any storage that will store a set of objects, and one of the object's fields be used as a key by which to search?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vladimir S, 2015-04-17
@Ramirag

I really liked the Dictionary, which uses a key field from the class as a key. But in this case, I need to remove the key field from the class and store it in the dictionary key. Of course, you can not delete it, but it will be duplicated.

Dictionary and use - I think in your case the best option, and search by key is very fast.

A
Alexander Dubina, 2015-04-20
@struggleendlessly

by the way, we compared ourselves, switch works 10 times faster than a dictionary .....
and to speed up, look at hash tables...

T
Tsiren Naimanov, 2015-04-17
@ImmortalCAT

List??

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question