How to get the list of files in a given directory using C#?

If I need to get a list of files of a particular type or extension in a given directory, how can I get that list using C# code. Here is an example where the code looks for files in the current directory with .txt extension and writes the list to the console.

You can change the code to look for any other particular directory instead of the current directory, just by specifying the directory path to the DirectoryInfo Class. Also you can get a list of files with any extension type just by providing the extension type to the GetFiles Method of the DirectoryInfo Class. (eg. “*.pdf” for pdf files or “*.*” for all files) 
using System;
using System.IO;
public class DirectoryList
    public static void Main(String[] args)
        string dirPath = Environment.CurrentDirectory;

        DirectoryInfo dir = new DirectoryInfo(dirPath);
        foreach (FileInfo f in dir.GetFiles("*.txt"))
            string fileName = f.Name;
            long fileSize = f.Length;
            DateTime fileCreationTime = f.CreationTime;
            Console.WriteLine("{0,-12:N0} {1,-20:g} {2}", fileSize,
                fileCreationTime, fileName);