Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

How to remove an item in a Generic List inside a foreach loop

$
0
0

When using a for loop it's easy to figure out what index to shove into the RemoveAt method on a generic list.  But I'm not sure how to do this in a foreach so easily:

            foreach (Item item in Items)
            {

                if(item == null)
                    // remove it from the Items generic list

                ....

             }


C# Web Developer

Viewing all articles
Browse latest Browse all 31927

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>