title: Write to CSV and text file
body: <p>In C# can someone teach me how to write the output of this program to a csv and a text file with unique ID each time? Like instead of writing to the console I want everything to go to a csv file and a text file at the same time. And also for the txt file includes a unique ID as record keeping.</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  
  namespace ConsoleApplication2
  {
  
  public class Product
  {
      public string description;
      public double price;
      public int count;
  
      public Product(string description, double price, int count)
      {
          this.description = description;
          this.price = price * count;
          this.count = count;
      }
  
      public string GetDetailLine()
      {
  
          return String.Format(count + " {0}: {1:c}", description, price);
      }
  }
  
  class Program
  {
      static void Main(string[] args)
      {
          int AdultTicket;
          int KidTicket;
          int PopcornOrder;
          int DrinkOrder;
          double tax = .05;
  
          List&lt;Product&gt; products = new List&lt;Product&gt;();
  
          Console.Write("How many adults? ");
          int.TryParse(Console.ReadLine(), out AdultTicket);
          Product adultTicket = new Product("Adult Ticket(s)", 7.75, AdultTicket);
          products.Add(adultTicket);
  
          Console.Write("How many kids? ");
          int.TryParse(Console.ReadLine(), out KidTicket);
          Product kidTicket = new Product("Kid Ticket(s)", 5.75, KidTicket);
          products.Add(kidTicket);
  
          Console.Write("Do you want popcorn? ");
          string input = Console.ReadLine();
          if (input.ToUpper() == "YES")
          {
              Console.Write ("How many? ");
              int.TryParse(Console.ReadLine (), out PopcornOrder);
              Product popcorn = new Product("Small popcorn", 3.50, PopcornOrder );
              products.Add(popcorn);
          }
  
          Console.Write("Do you want a drink? ");
          string input2 = Console.ReadLine();
          if (input2.ToUpper() == "YES")
          {
              Console.Write("How many? ");
              int.TryParse(Console.ReadLine(), out DrinkOrder);
              Product drink = new Product("Large Soda", 5.50, DrinkOrder);
              products.Add(drink);
              Console.Clear();
          }
  
  
  
          int count = 0;
          for (int i = 0; i &lt; products.Count; i++)
          {
              count += products[i].count;
          }
  
          double total = 0;
          for (int i = 0; i &lt; products.Count; i++)
          {                
              Console.WriteLine("\t\t" + products[i].GetDetailLine());
              total += products[i].price;
          }
  
          Console.WriteLine("\nYour sub total is:  {0:c}", total);
          Console.WriteLine("Tax: {0:c}", total * tax);
          Console.WriteLine("Your total is: {0:c}", total * tax + total);
          Console.ReadLine();
      }
  }
  </code></pre>
  
  <p>}</p>