I have this code:

private void words(string path)
        {
            List<string> text = new List<string>();
            var intro = "Video File Name:";
            var words = File.ReadAllLines(path)
                           .Where(line => line.StartsWith(intro))
                           .Select(line => line.Substring(intro.Length).Trim());    
        }

When i use a breakpoint and look after all on the variable words i see: System.Linq.Enumerable.WhereSelectArrayIterator<string,string>

I want to loop somehow on words and use each word how can i do it ?
The variable path is a text file that its content format is like this:

Video File Name: MVI_4523.MOV

Lightning Start Location At Frame: 11 Lightning End Location At Frame: 15
Lightning Start Location At Frame: 6 Lightning End Location At Frame: 15

Video File Name: MVI_4524.MOV

Lightning Start Location At Frame: 15 Lightning End Location At Frame: 19
Lightning Start Location At Frame: 4 Lightning End Location At Frame: 19

First part i want to get in a List<string> all the video files names for example:

index[0] MVI_4523.MOV
index[1] MVI_4524.MOV

Then i have in my code somewhere the variable videoFile a string variable.
I want to loop over the List<string> and compare and if videoFile == to one of the video files names in the List
Then extract the current lightnings start and end numbers into a int List.

For example:

if (videoFile == videosnames[i])
{
   ....extract here the frames belong to the video file name if it was MVI_4524.MOV then add to a int List 
   index[0] 15 19
   index[1] 4 19
}

Something like this.

I want to get the video file name and its belong lightnings frames values.

Essentially you only defined the query but you never executed it (this is called deferred execution). You should be able to correct that simply by putting .ToList() on the end of your LINQ.

var words = File.ReadAllLines(path)
                .Where(line => line.StartsWith(intro))
                .Select(line => line.Substring(intro.Length).Trim())
                .ToList();  

This will cause the query to execute and your words variable should contain a List<string>

Your loop can be achieved with foreach

foreach(string movieFileName in words.Where(str => videosnames.Contains(str)))
{
    // Do stuff here
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.