linq get a dictionary key and value c#
var values = dictionary.Where(x => someKeys.Contains(x.Key)).Select(x => x.Value);
var keys = dictionary.Where(x => someValues.Contains(x.Value)).Select(x => x.Key);
linq get a dictionary key and value c#
var values = dictionary.Where(x => someKeys.Contains(x.Key)).Select(x => x.Value);
var keys = dictionary.Where(x => someValues.Contains(x.Value)).Select(x => x.Key);
reading dictionary key value using linq and storig into a variable
public static class DictionaryHelper
{
public static IDictionary<string, double> LossPercentageDic()
{
var dictionaryLossPercentage = new Dictionary<string, double>();
dictionaryLossPercentage.Add("Less than 10%", 0.05);
dictionaryLossPercentage.Add("10% to 24%", 0.15);
dictionaryLossPercentage.Add("25% to 49%", 0.4);
dictionaryLossPercentage.Add("50% to 74%", 0.66);
dictionaryLossPercentage.Add("75% and more", 1);
return dictionaryLossPercentage;
}
}
//var Persons1 = values.Where(kvp => PersonList.Contains(kvp.Value))
// .ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
//var Persons = values.Where(kvp => kvp.Value == 0m)
// .ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
//var howMuchAffectedMainString = dictionaryLossPercentage
// .Where(kvp => kvp.Value == (double)aHousehold.HowMuchAffectedMain)
// .Select(x => new { Key = x.Key }).ToList().FirstOrDefault().Key;
var howMuchAffectedMainString = aHousehold.HowMuchAffectedMain != null ?
DictionaryHelper.LossPercentageDic()
.Where(kvp => kvp.Value == (double)aHousehold.HowMuchAffectedMain)
.Select(x => new { Key = x.Key }).ToList().FirstOrDefault().Key : "";
//dto mapping
HowMuchAffectedMain = aHousehold.HowMuchAffectedMain != null ?
DictionaryHelper.LossPercentageDic().Where(kvp => kvp.Value ==
(double)aHousehold.HowMuchAffectedMain)
.Select(x => new { Key = x.Key }).ToList().FirstOrDefault().Key : "",
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us