How can I define variables in LINQ?

Viewed 29040

This code:

string[] files = {"test.txt", 
    "test2.txt", 
    "notes.txt", 
    "notes.doc", 
    "data.xml", 
    "test.xml", 
    "test.html", 
    "notes.txt", 
    "test.as"};

files.ToList().ForEach(f => Console.WriteLine(
        f.Substring(
            f.IndexOf('.') + 1, 
            f.Length - f.IndexOf('.') - 1
            )
    ));

produces this list:

txt
txt
txt
doc
xml
xml
html
txt
as

Is there some way to make f.IndexOf('.') a variable so that in more complex LINQ queries I have this defined in one place?

3 Answers
Related