Questions tagged [keyvaluepair]

Defines a key/value pair that can be set or retrieved.

Defines a key/value pair that can be set or retrieved. The most common key/value pair used is HTTP GET paramaters which take the form of:

key1=value1&key2=value2&key3=value3

This syntax makes this type of storage very open-ended as you continue to append the next key/value pair to the end of the string.


In the mscorlib library (from MSDN)

Namespace: System.Collections.Generic

Type Parameters

TKey

The type of the key.

TValue

The type of the value.

Read more and view examples at MSDN

440 questions
125
votes
9 answers

Why can't I compile an unordered_map with a pair as key?

I am trying to create an unordered_map to map pairs with integers: #include using namespace std; using Vote = pair; using Unordered_map = unordered_map; I have a class where I have declared an…
Marre
  • 1,253
  • 2
  • 9
  • 7
51
votes
3 answers

Serialize List> as JSON

I'm very new with JSON, please help! I am trying to serialise a List> as JSON Currently: [{"Key":"MyKey 1","Value":"MyValue 1"},{"Key":"MyKey 2","Value":"MyValue 2"}] Expected: [{"MyKey 1":"MyValue 1"},{"MyKey…
maryhadalittlelamb
  • 741
  • 1
  • 7
  • 11
50
votes
1 answer

Key Value Pair List

I have a list with below elements: {[A,1] ; [B,0] ; [C,0] ; [D,2]; [E,0] ; [F,8]} When Variable =3 -> i want the return value to be A,D When variable =11 -> return value to be A, D, F when 2 -> return value to be D and so on. int sum =…
user2778395
  • 519
  • 1
  • 4
  • 6
42
votes
4 answers

Projecting into KeyValuePair via EF / Linq

I'm trying to load a list of KeyValuePairs from an EF / Linq query like this: return (from o in context.myTable select new KeyValuePair(o.columnA, o.columnB)).ToList(); My problem is that this results in the error "Only…
GrandMasterFlush
  • 6,269
  • 19
  • 81
  • 104
32
votes
5 answers

Creating the IEnumerable> Objects with C#?

For testing purposes, I need to create an IEnumerable> object with the following sample key value pairs: Key = Name | Value : John Key = City | Value : NY What is the easiest approach to do this?
Chathuranga Chandrasekara
  • 20,548
  • 30
  • 97
  • 138
22
votes
7 answers

C# get keys and values from List

Given a list: private List> KV_List = new List>(); void initList() { KV_List.Add(new KeyValuePair("qwer", "asdf")); KV_List.Add(new…
frog_jr
  • 361
  • 1
  • 2
  • 8
19
votes
3 answers

Convert list to params C#

I have this following list: var myList = new List>(); And this function: public void Test(params KeyValuePair[] list) How can I do a conversion of the list to params when using the function? Like…
AgresivD
  • 193
  • 1
  • 1
  • 4
19
votes
3 answers

c# Sorting a List>

In C# I would like to sort a List> by the length of each string in the list. In Psuedo-Java this would be an anonymous and would look something like: Collections.Sort(someList, new Comparator>(…
CodeKingPlusPlus
  • 15,383
  • 51
  • 135
  • 216
16
votes
2 answers

Add a Key Value Pair to an array of objects in javascript?

If I had an array as such: var myarray = []; myarray.push({ "Name": 'Adam', "Age": 33 }); myarray.push({ "Name": 'Emily', "Age": 32 }); This gives me an array where I can pull out values like myarray[0].Name which would give me…
jensanity5000
  • 324
  • 1
  • 3
  • 10
14
votes
1 answer

How to unpack key,value pairs in python?

I'm trying to explore the Algorithmia image taggers in python. client.algo("deeplearning/IllustrationTagger/0.2.5") client.algo("deeplearning/InceptionNet/1.0.3") But that's not quite relevant to this question, as it applies to dictionaries in…
13
votes
2 answers

Convert two lists of same size to key value pair in elixir

I'm trying to figure out the best way to combine two lists of the same size into a map of key value pairs. I've been using the same function to handle this case for a while for CSVs and raw SQL queries which return some sort of header list along…
13
votes
2 answers

KeyValuePair Covariance

Is there a better way to mimic Covariance in this example? Ideally I'd like to do: private IDictionary> foos; public IEnumerable> Foos { get { return foos; …
Ben Foster
  • 34,340
  • 40
  • 176
  • 285
12
votes
3 answers

Difference between Pair and Hashmap?

What is the necessity to introduce Pair class when Hashmap can do the same job? I see Pair being introduced to Java version 8
Mani
  • 2,599
  • 4
  • 30
  • 49
12
votes
2 answers

Python: Freeze dict keys after creation

Is it possible to "freeze" a python dict after creation so that it's impossible to add new keys to it? It would only be possible to change existing key values. If not, how do you know when you are changing an existing keyvalue pair, and when you are…
danihodovic
  • 1,151
  • 3
  • 18
  • 28
11
votes
5 answers

Is there a way to create hashmap in javascript and manipulate it like adding and deleting values

My requirement is to store key-value pairs in a data structure and fetch or delete the pairs when necessary using keys in JavaScript. How can I do it in JavaScript as one does it in Java? I have seen an answer creating an instance of hash map…
user1817439
  • 123
  • 1
  • 1
  • 4
1
2 3
29 30