Martin Thwaites wrote:
string keyToFind = "asdfgsd44rtgr"; Dictionary<string, object> dctTemp = GetDictionary(); object theObject = dctTemp.ToList().FirstOrDefault(x => x.key == keyToFind).Value;
Should be:
object theObject = GetDictionary()[keytoFind];
will return null if it's not in there, and with a dictionary you can only add one unique Key per...See:
using System.Collections.Generic;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
Class1.Sample();
}
static class Class1
{
private static Dictionary GetDictionary()
{
var retval = new Dictionary();
retval.Add("asdfgsd44rtgr", "1");
//Throws Error
//System.ArgumentException was unhandled
//Message=An item with the same key has already been added.
//Source=mscorlib
//StackTrace: {ommitted}
retval.Add("asdfgsd44rtgr", "throws error");
return retval;
}
public static void Sample()
{
string keyToFind = "asdfgsd44rtgr";
Dictionary dctTemp = GetDictionary();
//object theObject = dctTemp.ToList().FirstOrDefault(x => x.Key == keyToFind).Value;
object theObject = GetDictionary()\[keyToFind\];
}
}
}
}
or did I miss Something ?:confused:
I'd blame it on the Brain farts.. But let's be honest, it really is more like a Methane factory between my ears some days then it is anything else...
-----
"The conversations he was having with himself were becoming ominous."-.. On the radio...