Creating the IEnumerable Objects with C#?

any of: values = new Dictionary<string,string> { {“Name”, “John”}, {“City”, “NY”} }; or values = new [] { new KeyValuePair<string,string>(“Name”,”John”), new KeyValuePair<string,string>(“City”,”NY”) }; or: values = (new[] { new {Key = “Name”, Value = “John”}, new {Key = “City”, Value = “NY”} }).ToDictionary(x => x.Key, x => x.Value);

Projecting into KeyValuePair via EF / Linq

Select only columnA and columnB from your table, and move further processing in memory: return context.myTable .Select(o => new { o.columnA, o.columnB }) // only two fields .AsEnumerable() // to clients memory .Select(o => new KeyValuePair<int, string>(o.columnA, o.columnB)) .ToList(); Consider also to create dictionary which contains KeyValuePairs: return context.myTable.ToDictionary(o => o.columnA, o => o.columnB).ToList();

Serialize List as JSON

You can use Newtonsoft and dictionary: var dict = new Dictionary<int, string>(); dict.Add(1, “one”); dict.Add(2, “two”); var output = Newtonsoft.Json.JsonConvert.SerializeObject(dict); The output is : {“1″:”one”,”2″:”two”} Edit Thanks to @Sergey Berezovskiy for the information. You are currently using Newtonsoft, so just change your List<KeyValuePair<object, object>> to Dictionary<object,object> and use the serialize and deserialize method from the … Read more

Key Value Pair List

Using one of the subsets method in this question var list = new List<KeyValuePair<string, int>>() { new KeyValuePair<string, int>(“A”, 1), new KeyValuePair<string, int>(“B”, 0), new KeyValuePair<string, int>(“C”, 0), new KeyValuePair<string, int>(“D”, 2), new KeyValuePair<string, int>(“E”, 8), }; int input = 11; var items = SubSets(list).FirstOrDefault(x => x.Sum(y => y.Value)==input); EDIT a full console application: using … Read more

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

You need to provide a suitable hash function for your key type. A simple example: #include <unordered_map> #include <functional> #include <string> #include <utility> // Only for pairs of std::hash-able types for simplicity. // You can of course template this struct to allow other hash functions struct pair_hash { template <class T1, class T2> std::size_t operator … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)