[Mono-list] Re: Checking key existance in a NameValueCollection
Arnaud Bienvenu
arnaud.bienvenu@makina-corpus.org
Wed, 13 Oct 2004 17:44:26 +0200
Shawn Vose a écrit :
> I think it should be in a try statement because if the key doesnt exist
> it will throw an exception.
No, it will not. This is from NameValueCollection.Get documentation :
"Return Value : A String that contains a comma-separated list of the
values associated with the specified key from the NameValueCollection,
if found; otherwise, a null reference (Nothing in Visual Basic)."
I guess the [] operator uses the Get method. I made a test, it does not
throw any exception when I read Request.Form["nonexistantkey"]. You may
have mixed up things with another cool language, Python, where it would
throw a KeyError exception.
> Additionally in c# it would use [] instead of ()
This is right :)
--
Arnaud Bienvenu
Makina Corpus