开发者

convert a method into a getter

I have a generic method (in a non generic class) returning elements.

    public IEnumerable<T> GetElements<T>() where T : class
    {
        foreach (Element element in elements)
        {
            if (element is T)
            {
                yield return element as T;
            }
        }
    }

I want to transform this function in a getter method and tried something like

    开发者_StackOverflow中文版public IEnumerable<T> Elements<T>
    {
        get
        {
            foreach (Element element in elements)
            {
                if (element is T)
                {
                    yield return element as T;
                }
            }
        }
    }

This does not compile: ( expected

Some one knows what the problem is here?

thanks


Properties do not support generic parameters.

The only way to achieve something like this would be to supply a generic type parameter to the encapsulating type.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜