Note that there are some explanatory texts on larger screens.

plurals
  1. POc# - Find element value in an Object within a List within Dictionnary
    primarykey
    data
    text
    <p>I'm currently in needs of creating a Dictionary like that :</p> <pre><code>public Dictionary&lt;MyFirstObject, List&lt;MySecondObject&gt;&gt; _reference { get; set; } </code></pre> <p>These 2 objects store datas which need to be match during the process. This is why I used a Dictionary. The Objects looks like that :</p> <pre><code>public class MyFirstObject { public string _element1 ; public MyThirdObject _element2; public MyFirstObject(string element1, MyThirdObject element2) { _element1 = element1; _element2 = element2; } } public class MySecondObject { public string _element3; public string _element4; public string _element5; public MySecondObject(string element3, string element4, string element5) { _element3 = element3; _element4 = element4; _element5 = element5; } } </code></pre> <hr> <p>Than I would like to get the "<strong>MyFirstObject</strong>" which contain some data inside, for example I succeed to find the "<strong>_element1</strong>" and I got the related "<strong>MyFirstObject</strong>" of this request :</p> <pre><code>MyFirstObject mfo = _reference.FirstOrDefault(z =&gt; z.Key._element1 == "mySearch").Key </code></pre> <p>This code works ! I think that I could easily find the _element2 without problem. Now, I would like to do the same thing with the "<strong>Dictionary.Value</strong>" and find, for example, the "<strong>_element3</strong>".</p> <p>I tried this code :</p> <pre><code>MyFirstObject mfo = _reference.FirstOrDefault(x =&gt; x.Value.FirstOrDefault(z =&gt; z._element3 == "mySearch")).Key; </code></pre> <p>I used the "<strong>.Key</strong>" at the end because I would like to get the relative "<strong>MyFirstObject</strong>" of this request. But this request doesn't work.</p> <p>Can you help me to success this request please ?</p> <p>Thanks</p> <p>EDIT : the error message is : "<strong>Cannot implicitly convert type 'MySecondObject' to 'bool'</strong>"</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload