I have an custom UserControl I created
public class MyObject : UserControl
{
public MyObject()
{
}
public bool IsFinished { get; set; }
}
I added lets say 10(will be dynamic) MyObject‘s to a StackPanel and every other item i set IsFinished to true.
private void DoSomething()
{
StackPanel panel = new StackPanel();
for (int i = 0; i <= 10; i++)
{
int rem = 0;
Math.DivRem(i, 2, out rem);
MyObject newObj = new MyObject();
if (rem == 0)
{
newObj.IsFinished = true;
}
panel.Children.Add(newObj);
}
}
Now I can add the following and get the answer I am looking for (5)
int FinishedItems = 0;
foreach (object o in panel.Children)
{
if (o.GetType() == typeof(MyObject))
{
if (((MyObject)o).IsFinished)
{
FinishedItems++;
}
}
}
2 Questions:
A. Is there a more eloquent way? maybe with Linq I’m still learning how to use that. From what I understand, that is what LINQ technically does.
B. Am I wrong about LINQ?
So you want to count the finished items: