Hi,
I have a foreach loop that iterates through a list of files by their name, and then, in another class, still within the loop, opens each file and manipulates it in various ways.
When encountering a bad file (which I can easily detect), I wish to skip the file data manipulation, ignore that file and go to the next item (file name) in the foreach loop.
In short: How can one skip an item in foreach loop and continue with the next one?
Thanks
samatl
Veena SardaPosted Jun 5, 2014, 2:45 AM
SamPosted Jun 5, 2014, 4:32 AM
Abhishek KumarPosted Jun 5, 2014, 3:04 AM
Hope below example will help.
if you don't want to print David.
class Program students = new List();
{
static void Main(string[] args)
{
List
students.Add("Abhishek");
students.Add("Ramesh");
students.Add("David");
students.Add("Rekha");
foreach(string stud in students)
{
if (stud != "David")
{
Console.WriteLine("NameType is" + stud.ToString());
}
}
Console.ReadLine();
}
}
Abhishek