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
c#
|best-practices
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