Mcbeev.com

Taking it one line of code at a time

Blog Update

I finally decided it was time to update my blog. So we are now running version 1.6.1 of BlogEngine.Net. So far the upgrade has went well. You might see some small glitches, hopefully I can get them fixed before you notice.


I had a small crazy issue today with a web app that I'm working on dealing with looking up keys and values in a C# KeyValuePair<string, Guid> generic object.

I was using it to look in a Dictionary<string, Guid> of users. Makes sense to populate dropdowns with on the server, and use as a callback in cache to not have to look at the database every page load right ?

For some reason it was not finding some Keys, or users in my case, and finding others. I narrowed it down to when you log in, what you type might not match the case that the system has for you.

And sure enough when I logged in with mcbeev it was not finding Mcbeev. That's pretty strange I thought, SQL isn't case sensitive. Ah but the default Dictionary<T, T> uses whatever the default comparison operator for string is.

I was using the following

Dictionary<string, Guid> dict = new Dictionary<string, Guid>();

And after switching to

Dictionary<string, Guid> dict = new Dictionary<string, Guid>(StringComparer.CurrentCultureIgnoreCase);

Viola! it worked. I had never bothered looking at the other constructors for Dictionary<T,T>. One of them allows you to pass whatever kind of comparer your heart desires.


About Me

I have over 11 years of experience doing this crazy web development thing mainly at BizStream. I'm passionate about software platforms and technologies that can help solve real world problems. I enjoy hanging out with my wife, chasing around my three children and vigorously rooting for the Michigan State Spartans and Detroit Lions. (I know, right? Who still roots for the Lions?)

View Brian McKeiver's profile on LinkedIn

 

PhotoStream

Calendar

<<  September 2010  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

View posts in large calendar

last.fm

Kings of LeonCloser29 minutes ago
.38 SpecialFantasy Girl33 minutes ago
Dirty Pretty ThingsGin & Milk42 minutes ago
Little Man TateThis Must Be Love46 minutes ago
MilburnBrewster49 minutes ago
The HollowaysFit For A Fortnight53 minutes ago
Kings of LeonI Want You58 minutes ago
Hard-FiSuburban Knightsabout 27 days ago
AerosmithJust Push Playabout 27 days ago
DispatchMissionabout 27 days ago

Xbox GamerCard

Offline 9/6/2010 9:47:26 PM Last seen 09/07/10 playing Xbox 360 Dashboard