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);
}
}
Loading
David SmithPosted Oct 27, 2010, 7:15 AM
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
Sam HobbsPosted Oct 27, 2010, 3:35 AM
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.
Suthish NairPosted Oct 27, 2010, 1:48 AM
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 :-)
Sam HobbsPosted Oct 27, 2010, 1:08 AM
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.
David SmithPosted Oct 27, 2010, 12:11 AM
Suthish NairPosted Oct 26, 2010, 2:03 PM
David SmithPosted Oct 26, 2010, 12:59 PM
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);
}