Click here to Skip to main content
15,881,826 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Could somebody please provide a clear example that shows how to use the foreach statement?
Posted
Updated 29-Jun-11 0:36am
v2

C#
foreach(Apostle prophet in God.Apostles)
{
    prophet.WriteScriptures();
}
 
Share this answer
 
Comments
Tarun.K.S 29-Jun-11 6:25am    
Hhahahahahahaha! Hilarious!
ambarishtv 29-Jun-11 7:38am    
LoL
Sergey Alexandrovich Kryukov 30-Jun-11 4:49am    
My 5. However you should have explained that Apostles should support IEnumerable. Amen.
--SA
try this link :thumbsup:
http://msdn.microsoft.com/en-us/library/ttw7t8t6.aspx[^]
-Ambi-
 
Share this answer
 
Comments
Tarun.K.S 29-Jun-11 6:22am    
That should help. 5!
ambarishtv 29-Jun-11 6:23am    
thank you Tarun
Another example of foreach is,

C#
string[] stringArray = { "C#"," ","Framework 4.0" };
Array.ForEach(stringArray, item =>
{
    Console.WriteLine(item);
});


:)
 
Share this answer
 
Comments
[no name] 16-Jul-11 13:51pm    
You are only adding confusion here, the questioner just wants a plain example of using 'foreach' statement, there was no need to give him this inappropriate example.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900