Click here to Skip to main content
15,941,973 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
i want program for even and old in for each loop
Posted
Updated 21-Nov-12 20:55pm
v2
Comments
Sergey Alexandrovich Kryukov 22-Nov-12 2:52am    
This is not a question. If you want to have a program, go ahead and write it.
--SA
OriginalGriff 22-Nov-12 2:52am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
Use the "Improve question" widget to edit your question and provide better information.
ridoy 22-Nov-12 3:07am    
not a question..

1 solution

C#
int[] collection = new int[] { -2, -1, 0, 1, 2, 3, 4, 5, 6, 7 };
string result;
foreach(int number in collection)
{
    if (number % 2 == 0) // even (or zero)
        result = "it's even!";
    else
        result = "that's odd...";
}
 
Share this answer
 
v2
Comments
sumit kausalye 22-Nov-12 4:25am    
now can pass the collections values to database or can i fetch the records from database? how? by using foreach loop
markovl 22-Nov-12 4:40am    
OK, you need to pick up a beginner's book and start there.
The loop is so basic a concept that if you don't understand it, you should stop right here, go back and start doing some serious reading and experimenting. After you've grasped on the basics, you could go to more advanced scenarios.

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