Hello,
I am sorry if the question sounds stupid but I am kind of learning programming on my own using c#.
Q1: I am wondering what are the typical use cases for array, list and dictionnary?
I used a bit of each so far, but I am not very confident when it comes to chose one over the other. My undertstanding so far is that array are “stupid” storage places of “infinite dimentions” (2^64-ish), Lists are intelligent 1D storage places and Dictionnary intelligent “1,5D” storage where I can link a key with a value.
Q2: is that right?
Q3: what is the advantage of dictionary over lists?
Until today I thought dictionary is used when I want to pair 2 pieces of data, with the drawback that it is easy to find a value based on a key but not to find back a key based on the value. I used it for example in the “MIME Type” challenge, where it worked well, and in the Scrabble challenge where it worked, I think, less well
(I created a dictionnary with all the words and their associated points value, and ended up with this construct which might go against the idea of a dictionary:
foreach(KeyValuePair<string, int> entry in dictWordValues)
{
if(IsWordPlayable (entry.Key, LETTERS) & entry.Value > bestValue)
{ ... }}
Today, while solving “Skynet: the Virus” (Ambush: check \o/), I decided to use lists for the first time. I made a list of links. I imagined the list to be just some pimped up arrays, and then I discovered I was (partially) wrong.
if (linkList.Exists(agentLink)) {...}
This did not compile. I took me a little to understand what is this Predicate the MSDN help wants me to give as datatype. And now it seems both very convenient and very “powerful”. Even more powerful then dictionary since I can access and filter the object of my list based on all public properties and method I define for them. I am not limited to 2. For instance, with that new knowledge in mind, I would approach the problem differently (I used 2 lists of strings, one for the links and the other for the removed links. Instead I could define a link class with both nodes as datas, as well as the string representation of the link, a boolean telling weither the link has been severed and any other informations (# of neighbours link, if it connects to a gateway, if it could be used to “trap” the agent and shorten the puzzle… etc) and just access them from the list).
Q4: Is this best practice?
Q5: Should I manipulate an object stored in a list (in the Skynet challenge, set a “link cut” boolean to true when cuting a link)? If yes, what is the best way to do it?
Thanks in advance, and sorry for the long “narrative” post. It is easier for me to reflect my experience “in the first person” to define the frame of my questions
Cheers