code_junkie

Merging 2 Collection<T>

Nov 10th, 2011
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. public IEnumerable<string> Combine(IEnumerable<string> col1, IEnumerable<string> col2)
  2. {
  3. foreach(string item in col1)
  4. yield return item;
  5.  
  6. foreach(string item in col2)
  7. yield return item;
  8. }
  9.  
  10. class Program
  11. {
  12. static void Main(string[] args)
  13. {
  14. Collection<string> myitems = new Collection<string>();
  15. myMthod(ref myitems);
  16. Console.WriteLine(myitems.Count.ToString());
  17. Console.ReadLine();
  18. }
  19.  
  20. static void myMthod(ref Collection<string> myitems)
  21. {
  22. myitems.Add("string");
  23. if(myitems.Count <5)
  24. myMthod(ref myitems);
  25. }
  26. }
Add Comment
Please, Sign In to add comment