c# - Return a property from an object found using a delegate searching for a different property? -


so, after wonderful , impossible understand title, here problem. have button object:

class button {     public texture2d texture {get;set;}     public string name {get;set;}     ... } 

i'm holding list of buttons in list<button> buttons. @ point in code, need return texture property button. can't sure of value of it, can't search button it's texture value. need search name. i'm using delegate:

somemethod(buttons.find(delegate (button btn)  {     return btn.name = "title"; })); 

however, can't return texture property way, unless create temporary button object.

so, how return texture property, searching name ?

you can use linq:

texture2d thetexture = buttons                         .where(b => b.name = "title")                         .select(b => b.texture)                         .first(); 

if want handle "no matches", can use .firstordefault(), cause return null if there no matching name.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -