is the below a good approach to returning a safe list enumerator?

Posted by user200295 on Stack Overflow See other posts from Stack Overflow or by user200295
Published on 2010-04-21T14:23:38Z Indexed on 2010/04/21 14:33 UTC
Read the original article Hit count: 238

Filed under:
|
 public class Foo{
        public string Prop1 {get;set;}
        public string Prop2 {get;set;}

        public Foo(Foo source) {
            this.Prop1 = source.Prop1;
            this.Prop2 = source.Prop2;
        }
    }

    public class Main
    {
        private List<Foo> items = new List<Foo>();

        public IEnumerable<Foo> GetItems() {
            foreach (Foo foo in items) {
                yield return new Foo(foo);
            }
        }
    }

© Stack Overflow or respective owner

Related posts about c#

Related posts about best-practices