namevaluecollection

NameValueCollection not available from System.Collections.Specialized

爱⌒轻易说出口 提交于 2019-12-02 03:10:27
In VS 2012 Express for Windows Phone, I am using imports of both System and System.Collections.Specialized , but I still get an error when trying to use NameValueCollection . Looking in the Object browser, I see it nested within System.dll, but there are several versions of the System dll listed - some of which do not have it. What I get in auto-complete matches the available items in the System.dll without NameValueCollection , so I'm thinking I need to sort out which System.dll is being used, but I am not sure how to do so. Can someone help me to use NameValueCollection ? The System versions

Check if Key Exists in NameValueCollection

不想你离开。 提交于 2019-11-28 18:30:15
Is there a quick and simple way to check if a key exists in a NameValueCollection without looping through it? Looking for something like Dictionary.ContainsKey() or similar. There are many ways to solve this of course. Just wondering if someone can help scratch my brain itch. abatishchev From MSDN : This property returns null in the following cases: 1) if the specified key is not found; So you can just: NameValueCollection collection = ... string value = collection[key]; if (value == null) // key doesn't exist 2) if the specified key is found and its associated value is null. collection[key]

C# Iterate through NameValueCollection

 ̄綄美尐妖づ 提交于 2019-11-28 16:56:37
I have a NameValueCollection , and want to iterate through the values. Currently, I’m doing this, but it seems like there should be a neater way to do it: NameValueCollection nvc = new NameValueCollection(); nvc.Add("Test", "Val1"); nvc.Add("Test2", "Val1"); nvc.Add("Test2", "Val1"); nvc.Add("Test2", "Val2"); nvc.Add("Test3", "Val1"); nvc.Add("Test4", "Val4"); foreach (string s in nvc) foreach (string v in nvc.GetValues(s)) Console.WriteLine("{0} {1}", s, v); Console.ReadLine(); Is there? Julian You can flatten the collection with Linq, but it's still a foreach loop but now more implicit. var

NameValueCollection vs Dictionary<string,string> [duplicate]

末鹿安然 提交于 2019-11-28 15:51:11
Possible Duplicate: IDictionary<string, string> or NameValueCollection Any reason I should use Dictionary<string,string> instead of NameValueCollection? (in C# / .NET Framework) Option 1, using NameValueCollection: //enter values: NameValueCollection nvc = new NameValueCollection() { {"key1", "value1"}, {"key2", "value2"}, {"key3", "value3"} }; // retrieve values: foreach(string key in nvc.AllKeys) { string value = nvc[key]; // do something } Option 2, using Dictionary<string,string>... //enter values: Dictionary<string, string> dict = new Dictionary<string, string>() { {"key1", "value1"}, {

Getting a Request.Headers value

…衆ロ難τιáo~ 提交于 2019-11-28 06:18:41
Very simple I'm sure, but driving me up the wall! There is a component that I use in my web application that identifies itself during a web request by adding the header "XYZComponent=true" - the problem I'm having is, how do you check for this in your view? The following wont work: if (Request.Headers["XYZComponent"].Count() > 0) Nor this: if (Request.Headers.AllKeys.Where(k => k == "XYZComponent").Count() > 0) Both throw exceptions if the header variable has not been set. Any help would be most appreciated. Sunday Ironfoot if (Request.Headers["XYZComponent"].Count() > 0) ... will attempted to

Make NameValueCollection accessible to LINQ Query

◇◆丶佛笑我妖孽 提交于 2019-11-27 18:05:22
How to make NameValueCollection accessible to LINQ query operator such as where, join, groupby? I tried the below: private NameValueCollection RequestFields() { NameValueCollection nvc = new NameValueCollection() { {"emailOption: blah Blah", "true"}, {"emailOption: blah Blah2", "false"}, {"nothing", "false"}, {"nothinger", "true"} }; return nvc; } public void GetSelectedEmail() { NameValueCollection nvc = RequestFields(); IQueryable queryable = nvc.AsQueryable(); } But I got an ArgumentException telling me that the source is not IEnumerable<> . You need to "lift" the non-generic IEnumerable to

Check if Key Exists in NameValueCollection

柔情痞子 提交于 2019-11-27 11:23:52
问题 Is there a quick and simple way to check if a key exists in a NameValueCollection without looping through it? Looking for something like Dictionary.ContainsKey() or similar. There are many ways to solve this of course. Just wondering if someone can help scratch my brain itch. 回答1: From MSDN: This property returns null in the following cases: 1) if the specified key is not found; So you can just: NameValueCollection collection = ... string value = collection[key]; if (value == null) // key

C# Iterate through NameValueCollection

有些话、适合烂在心里 提交于 2019-11-27 10:04:33
问题 I have a NameValueCollection , and want to iterate through the values. Currently, I’m doing this, but it seems like there should be a neater way to do it: NameValueCollection nvc = new NameValueCollection(); nvc.Add("Test", "Val1"); nvc.Add("Test2", "Val1"); nvc.Add("Test2", "Val1"); nvc.Add("Test2", "Val2"); nvc.Add("Test3", "Val1"); nvc.Add("Test4", "Val4"); foreach (string s in nvc) foreach (string v in nvc.GetValues(s)) Console.WriteLine("{0} {1}", s, v); Console.ReadLine(); Is there? 回答1

NameValueCollection vs Dictionary<string,string> [duplicate]

ⅰ亾dé卋堺 提交于 2019-11-27 09:23:17
问题 Possible Duplicate: IDictionary<string, string> or NameValueCollection Any reason I should use Dictionary<string,string> instead of NameValueCollection? (in C# / .NET Framework) Option 1, using NameValueCollection: //enter values: NameValueCollection nvc = new NameValueCollection() { {"key1", "value1"}, {"key2", "value2"}, {"key3", "value3"} }; // retrieve values: foreach(string key in nvc.AllKeys) { string value = nvc[key]; // do something } Option 2, using Dictionary<string,string>... /

NameValueCollection to URL Query?

我的未来我决定 提交于 2019-11-27 06:43:11
I know i can do this var nv = HttpUtility.ParseQueryString(req.RawUrl); But is there a way to convert this back to a url? var newUrl = HttpUtility.Something("/page", nv); Ahmad Mageed Simply calling ToString() on the NameValueCollection will return the name value pairs in a name1=value1&name2=value2 querystring ready format. Note that NameValueCollection types don't actually support this and it's misleading to suggest this, but the behavior works here due to the internal type that's actually returned, as explained below. Thanks to @mjwills for pointing out that the HttpUtility.ParseQueryString