So, after this wonderful and probably impossible to understand title, here is my problem.
I have this Button object:
class Button
{
public Texture2D Texture {get;set;}
public string Name {get;set;}
...
}
I’m holding a list of all the buttons in a List<Button> buttons. At some point in the code, I need to return the Texture property from a Button. I can’t be sure of the value of it, so I can’t search the button from it’s Texture value. I need to search its name. I’m currently using a delegate:
SomeMethod(buttons.Find(delegate (Button btn)
{
return btn.Name = "Title";
}));
However, I can’t return the Texture property this way, unless I create a temporary Button object.
So, how would I return the Texture property, by searching it by its Name ?
You can use LINQ:
If you want to handle “no matches”, you can use
.FirstOrDefault(), which will cause it to return null if there is no matching Name.