Export data from matrix to txt file I am new at programming and I'm really confused about how should I do this, because at first I thought I should ask user which path to export. However I have been told that I should check if it exists the directory and if doesn't I should create it. How can I even create a directory path or ask user if it can be created? Sorry if my question is too odd but I'm very confused about this, I was convinced that simply asking was enough to export data.   

static void exportData(string[,] matrix)
{

    var dir = "";
    do
    {
        Console.Clear();
        Console.Write("Insert path to export txt: ");
        dir = Console.ReadLine();
    } while (String.IsNullOrEmpty(dir));

    var path = Path.Combine(dir, "export.txt");


    using (StreamWriter sw = File.CreateText(path))
    {

        for (int i = 0; i &lt; matrix.GetLength(0); i++)
        {
            for (int j = 0; j &lt; matrix.GetLength(1) - 1; j++)
            {

                {
                    sw.Write($"\t{matrix[i, j]}\t");
                }

            }
            Console.WriteLine("\n");
        }

    }
As I correctly understood, you want to export matrix in text file.
If its true, your code contains some mistakes:

for (int j = 0; j &lt; matrix.GetLength(1) - 1; j++)


should be without decreasing length by 1 and Console.WriteLine("\n");
should be sw.WriteLine();

Also there is a not good idea to ask user to write a path. You could try to use SaveFileDialog instead. 

Full solution 

class Program
{
    [STAThread]
    static void Main(string[] args)
    {
        int[,] matrix = new int[3, 2]
        {
            {1, 2},
            {3, 4},
            {5, 6}
        };
        ExportData(matrix);
    }
    private static void ExportData(int[,] matrix)
    {
        var saveFileDialog = new SaveFileDialog
        {
            Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*",
            FileName = "export.txt"
        };

        if (saveFileDialog.ShowDialog() == DialogResult.OK)
        {
            using (StreamWriter streamWriter = new StreamWriter(saveFileDialog.FileName))
            {
                for(int i = 0; i &lt; matrix.GetLength(0); i++)
                {
                    for(int j = 0; j&lt; matrix.GetLength(1); j++)
                    {
                        streamWriter.Write($"\t{matrix[i, j]}\t");
                    }
                    streamWriter.WriteLine();
                }
            }
        }
    }
}


Just don't forget to add reference to System.Windows.Forms