Novice question. What collection type should I use to store such structure?
Files collection
---------------
FileId: Int
FileName : String
Path: String
I will need to store several files data into that collection, find Path by FileId field, delete item by FileId field.
Since you have several pre-defined pieces of information that you want associated with each value instance, I would start by defining a structure to hold the information required for each file:
And then I would use a generic collection (such as a
List<T>) to hold instances of that structure:Alternatively, you could use a
Dictionary<TKey, TValue>, with theFileIdas the key and theFileInfostructure as the value. For example:The advantage of a dictionary is that it provides faster lookup time when searching for a file by its ID. This is because a dictionary is implemented internally using a hash table.
EDIT: Note that mutable structs are evil. If you need to be able to change the individual pieces of information that describe a file (and I can’t imagine why you would), you should declare
CustomFileInfoas aclassinstead of astruct.