I have this data :
public class MetaLink
{
public long LinkNumbering { get; set; }
public long TargetPageId { get; set; }
public string TargetUrl { get; set; }
public LinkType LinkOfType { get; set; }
}
public static ConcurrentDictionary<int, List<MetaLink>> Links = new ConcurrentDictionary<int, List<MetaLink>>();
How can I obtain all index of MetaLink
object in the list dictionnary values and the correspondig dictionnary key with TargetUrl
property == "Some value"
Perhaps is possible with Linq, but I don't find it. I do this :
var someLinks = Links.Values.Where(kvp => kvp.Any(ml => ml.TargetUrl == "Some value"));
But I can't get the correspondig dictionnary int key
LeMousselLeMoussel
asked Oct 5, 2015 at 15:51
-
Your run-on sentence is really hard to parse. It would be much easier to help if you if you'd give a concrete example with sample input and expected output - ideally with what you've tried so far, too.Jon Skeet– Jon Skeet2015年10月05日 15:54:41 +00:00Commented Oct 5, 2015 at 15:54
2 Answers 2
You're close - you want
var someLinks = Links.Where(kvp => kvp.Value.Any(ml => ml.TargetUrl == "Some value"))
// all key.value pairs where the Value contains the target URL
.Select(kvp => kvp.Key); //keys for those values
answered Oct 5, 2015 at 16:29
Sign up to request clarification or add additional context in comments.
Comments
Give a try on this. Haven't compiled.
var key = Links.Where(kvp => kvp.Value.Any(ml => ml.TargetUrl == "Some value")).Select(x => x.Key).SingleOrDefault();
answered Oct 5, 2015 at 16:23
Comments
lang-cs