Search code examples
c#fileload

how to load a .dat file during program start with < operator C#


i have a *.dat file and i should load it when i start the program in the command line. e.g. programm.exe < data.dat

the dat file contains just a 2D structure made of some signs. e.g.

################
................
################
................
################
................

i want to load it and show it in WinForms.

If anyone has a hint where the "<" is specified. I just got the hint that i can be done without filehandling


Solution

  • if command line always is programm.exe < data.dat then you can use:

    static void Main(string[] args)
    {
        string input = System.Console.In.ReadToEnd();
    }
    

    if the input is missing, this will wait for user input. you can use async preventing to block program execution when input is missing or is loading.

    static void Main(string[] args)
    {
        string input = "";
        Task.Run(async () => { input = await System.Console.In.ReadToEndAsync(); });
    }