I have a simple object like this
public class Test
{
public string Name {get; set;}
}
Later I have List<Test> tests
And then I have a method which does something with a Test object in the List.
private void DoSomething(Test test)
{
//do some serious stuff here!
}
Then in the applciation, this Test objects will be populated in a TreeView and after user clicks them they will be passed to the method above. At the moment I find selected treenode like this:
string name = selectedNode.Text;
foreach(Test test in tests)
{
if (test.Name = name) DoSomething(test);
}
So the idea is, I cant figure out a way to use LINQ in the parameter of the method instead of doing that boring foreach loop.
this.DoSomething(from x in tests where x.Name = "What I need to pass" select x)
what is wrong?
Thanks!
1 Answer