public static void DeleteWhenFoundInTree(LocalAlbum alb, ref LocalAlbumList lstAlbum) { LocalAlbum treeAlb = null; for (int i = 0; i < lstAlbum.Count; i += 1) { treeAlb = lstAlbum.FirstOrDefault(a => a.LocalDir == alb.LocalDir); if (treeAlb != default(LocalAlbum)) { DeleteAlbum(ref treeAlb); lstAlbum.RemoveAt(i); return; } } for (int i = 0; i < lstAlbum.Count; i += 1) { LocalAlbumList FoundInLstAlb = lstAlbum[i].SubAlbums; DeleteWhenFoundInTree(alb, ref FoundInLstAlb); } }