Geeks With Blogs
Stefan Barrett blog

I do like the generics, but sometimes I think Microsoft have tried to simplyfy them to much. They've made it to hard to do the odd things. An example; recently
I was working with a list of name value pairs, so I used a Dictionary:
 Dictionary<string, object>
Everything was going fine, until I realised that in a default situation I needed the first value; regardless of name. I ended up writting a function looking
something like:
private object GetValue()
 foreach (KeyValuePair<string,object> item in Values)
  return item.Value;
 return null

What I would have prefered to do was something like:
 return values[values.Keys[0]]

Have really got to fix the snippits, so many things depending on them. I wonder if a simply re-install will do it...

Going to TechEd 2006 Boston. Have just booked my trip.Should be fun.

Seems you can check in on the Saturday now, and there's some sort of keynote on the Sunday.

Posted on Tuesday, February 7, 2006 4:31 AM | Back to top

Comments on this post: Getting to items in dictionaries

# re: Getting to items in dictionaries
Requesting Gravatar...
as for "return values[values.Keys[0]]"
A) what happens when values.Keys.Count<1? the default "generic" implementation had to be deferred to each particular collection.

i do agree that the return statement is more elegant.
Left by Eric Newton on Feb 08, 2006 10:37 PM

Comments have been closed on this topic.
Copyright © Stefan Barrett | Powered by: