❔ Basic question on linear search in list

RRonnie12/12/2022
Hello, I am making a blog/notebook for an assignment and I have a list which contains vectors with 3 elements, title/date/body - i need to do a linear search for a title but I cant find any information on how to loop through the first element on all the vectors in the list, any ideas?

Also, i have a DateTime-variable that is declared in the switch function, do i need to declare this at the top before using in Case 1?`

Help much appreciated : - P
Image
AAngius12/12/2022
foreach (var book in books)
{
    var title = book[0];
}
AAngius12/12/2022
Should be as simple as that
AAngius12/12/2022
Or, if LINQ is permitted, you can do
foreach (var title in books.Select(book => book[0]))
{
    // ...
}
AAngius12/12/2022
Though seeing how you use an array instead of a class to represent a book, whatever course you're taking didn't even touch on classes yet
AAngius12/12/2022
So LINQ being permitted or talked about is unlikely
RRonnie12/12/2022
We have touched on classes but i was specifically told not to use it for this assignment and to include a basic linear search for a title : - )

hmm soo.. i dont really understand, can you advice me what is wrong here on why this doesnt work?
RRonnie12/12/2022
Image
AAngius12/12/2022
blogPostList[i] is an array
AAngius12/12/2022
You can't compare an array to a string
AAngius12/12/2022
The array of a book, far as I can tell, has the title on the 0th index
AAngius12/12/2022
So you should do searchWord == blogPostList[i][0]
RRonnie12/12/2022
aaaaaaaaah! so [i][0] vill check index 0 of all objects in array?
RRonnie12/12/2022
that was the missing piece, thank you! 😄
AAccord12/13/2022
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.