TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
David Smith
NA
2k
0
how to Move to the next row within a foreach,
Oct 26 2010 11:30 AM
How to move to the next row within in a foreach
foreach (var row in TemCodes)
{
//Get test start time by operation
if (row.Code== "0001")
{
I want to move to the row
then move again
then move one more time
StartingTime = GetTime(0001, 0002, 0003);
}
}
Reply
Answers (
7
)
0
David Smith
0
2k
0
Oct 27 2010 7:15 AM
Yea that was to much but information, I kept the question to simple as possible, and I fix my own problem. @Suthish Nair being that I just really learn linq, I basically re-did my whole software
and replacing it with linq, because linq is powerful when you know what you are doing. So I replacing old logic with linq where it is needed and truly effective in my crude data interpreting. The linq has truly got the software to understandable and have my software running much faster than way I was processing before, but keep in mind im learning linq as I go.
I only need specific help which I solved already.
I don't know why this was confusion: The question was simply How to the next row within a foreach loop, Meaning if im in a foreach loop, and i come across lets say a if statement and jump into the case, I might want to view the next three rows without going to the top of foreach and get data because I need it for whatever reason. The reason why I wanted to go to the next rows within a foreach , the infomation im getting I have to now make a unique key. Its so many layers of extraction, thats why I didnt go deeper than I needed to, I kept it the specific question.
@Sutthish to answer your question Im using linq, and to the problem solve.
What was confusing about how to go the next row without going back to the top of the foreach loop.
Keep in my mind Im using a dictionary with a unique key and checking to see if the unique
key exists and if it dont add the record.
Laugh out Loud , I'm done explaining, the more I explain the complicated its going to get lololololol. Don't worry about it, all we need to know I found how to get the current index or record within a foreach and was able to move to the next couple of rows to extract pieces of information to make a unique key my dictionary
0
Sam Hobbs
54
29.3k
2.1m
Oct 27 2010 3:35 AM
I need to be careful not to say too much since this is for a major commercial (as in big business not big advertisement) project but there is data coming from a micro-controller so the data is squeezed into 4-byte pieces. So a timestamp (date and time) is in 3 pieces of 4 bytes each. The data is actually a bit more complicated than that so the solution is not entirely as simple as I described previously, but I think the solution described here is more crude than what it should be.
The project is definitely not a hobby or class assignment or anything such as that. It is for a real product with a very large staff. I think what they should do is to read the data in from the micro-controller and put it into object-oriented classes and then process those objects. There are many types of data in the sense of many formats and definitions and the data goes into a database. The challenge is to design an object-oriented system in which the various object types can be stored in the database in a variety of tables, separate tables for each type of data, but they are not doing that. Instead the data is stored in a relatively crude manner in the database; something that remains crude due to the limited capabilities of the micro-controllers.
0
Suthish Nair
0
30.5k
7.2m
Oct 27 2010 1:48 AM
I got bit confused, what he trying to say.
This the logic he want to check, then why need a loop (can try with linq). if (row.Code== "0001")
Or something else he upto, just for my knowledge :-)
0
Sam Hobbs
54
29.3k
2.1m
Oct 27 2010 1:08 AM
Darnell:
since you don't show what TemCodes is no one could help unless they guess and they might guess wrong. Also you don't explain why you need to get the subsequent items and you don't speciy whether any item needs to be processed more than once. Since I probably know what your data looks like, if I do know, then I can say that what you should say is that you need to process the data in sets of four. You need to find the set of four items in which the first item's Code is 0001, then get the next three items to convert that to a timestamp. To help you with that, people need to know what TemCodes is.
Suthish:
if I know what the data is, and I probbly do, then we don't need the sample code and we would not suggest it be used by others. Excuse me for speaking for you if I am wrong, but I think I know you well enough to say that you would not do things this way. What we would do is to process the data and put all four items into one class so it can be easily accessed. I tried to get Darnell to do that Darnell does not understand.
0
David Smith
0
2k
0
Oct 27 2010 12:11 AM
Before I explain for my situation can you tell me another way to move to next row within in a foreach, if you cant tell me then I will explain why i needed this logic which works perfect for me
0
Suthish Nair
0
30.5k
7.2m
Oct 26 2010 2:03 PM
hi why we need this kind of logic?
0
David Smith
0
2k
0
Oct 26 2010 12:59 PM
Nevermind you guys, for those who wants to know how to cheat the system in moving to the next row is simply to do this logic below
foreach (var row in TemCodes)
{
rowIndex
=
TemCodes.IndexOf(row); // Get the exact location of or index of where you at in the foreach, so then if you want to move , you just say rowIndex + ??????
var nextRow2 =
TemCodes[rowIndex + 1];
var nextRow3 =
TemCodes[rowIndex +2];
//Get test start time by operation
if (row.Code== "0001")
{
string 0001=
nextRow.?????
string 0002= nextRow2.?????
string 0003= nextRow3.?????
StartingTime = GetTime(0001, 0002, 0003);
}
silvelight
Validating PDF file in c#