【问题标题】:Find how many children you have of a certain type?找出你有多少特定类型的孩子?
【发布时间】:2019-04-02 13:09:45
【问题描述】:

我有一个画布,我将在其中添加一些矩形。我想知道我有多少个只有矩形的孩子。很像array.length

我试过这段代码,但没有运气

int count = plain.Children.OfType<Rectangle>.Count;

PlainCanvas 的名称。

但得到错误:

'Queryable.OfType(IQuerable)' 是一个方法,它是无效的 在给定的上下文中。代码 CS0119。

【问题讨论】:

    标签: c# wpf linq oop


    【解决方案1】:

    调用OfTypeCount方法时需要加括号:

    int count = plain.Children.OfType<Rectangle>().Count();
    

    【讨论】:

    • 谢谢。现在完美运行。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-25
    • 1970-01-01
    • 2020-04-10
    • 2020-07-05
    • 2011-05-12
    • 1970-01-01
    相关资源
    最近更新 更多