implement a cat program in csharp

Here's a basic implementation of a cat program in C#:

main.cs
using System;
using System.IO;

class CatProgram
{
    static void Main(string[] args)
    {
        if (args.Length == 0)
        {
            Console.WriteLine("Usage: cat <file1> [<file2> ...]");
            return;
        }

        foreach (string filename in args)
        {
            try
            {
                using (StreamReader reader = new StreamReader(filename))
                {
                    while (!reader.EndOfStream)
                    {
                        string line = reader.ReadLine();
                        Console.WriteLine(line);
                    }
                }
            }
            catch (FileNotFoundException)
            {
                Console.WriteLine($"File not found: {filename}");
            }
        }
    }
}
788 chars
34 lines

This program takes the names of one or more files as command-line arguments, and outputs their contents to the console. If any file is not found, it prints an error message for that file and continues with the rest of the files. The using statement ensures that the reader is properly disposed of when it's no longer needed.

gistlibby LogSnag