title: C# simple console app stock trading
body: <p>Hi I’m new to C# and I am trying to build a very simple stock tracking console application where a user inputs some info about a stock and the program saves and uses the input.  I’ve been going through online tutorials but I cannot seem to put it all together.  </p>
  
  <p>I want to ask a user to choose whether they want to sell a stock, buy a stock, or exit the program.  If they choose buy or sell a stock the program will ask them to enter the stock ticker, amount of stock purchased and price paid.  </p>
  
  <p>In this case I want the user to be able to continue to buy stock or sell stock until they choose to exit the application.  The program should track the total amount of stock the user has for each ticker.  For example, the user can input they purchased 100 shares of APPL stock on 2/1/12, then enter they purchased an additional 50 shares of APPL stock on 2/15/12, and then sold 25 shares of APPL stock on 3/1/12.  </p>
  
  <p>The program will track the info and when the user chooses to exit, the program will output how many shares they have left.  In the above example they have 125 shares left.  </p>
  
  <p>Eventually I want to turn this into a real-time stock trading program, but for now I'm just taking baby steps.</p>
  
  <p>I have include the code I have written so far below.  I don't understand the best way to handle the user input.</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Collections;
  
  namespace StockTracker
  {
  class Program
  {
      static void Main(string[] args)
      {
  
          while (true)
          {
              Console.WriteLine("Welcome to the Stock Tracker");
              Console.WriteLine("--------------------------------");
              Console.WriteLine("Please choose from the following options:");
              Console.WriteLine("1) Buy Stock, 2) Sell Stock, 0) Exit");
  
              ArrayList Array1 = new ArrayList();
              ArrayList Array2 = new ArrayList();
  
              string userValue = Console.ReadLine();
              string message = "";
  
  
              double price;
              int amount;
              string stockTicker;
  
  
              switch (userValue)
              {
  
                  case "1":
                      Console.WriteLine("Enter ticker to buy:");
                      stockTicker = Console.ReadLine();
                      Array1.Add(stockTicker);
                      Console.WriteLine("Enter stock price");
                      price = double.Parse(Console.ReadLine());
                      Array1.Add(price);
                      Console.WriteLine("Enter Quantity");
                      amount = int.Parse(Console.ReadLine());
                      Array1.Add(amount);
                      Console.WriteLine("***Stock Purchased***");
                      break;
  
  
                  case "2":
                      //message = "Enter stock ticker to sell";
                      Console.WriteLine("Enter stocker ticker to sell");
                      stockTicker = Console.ReadLine();
                      Array2.Add(stockTicker);
                      Console.WriteLine("Enter Quantity");
                      amount = int.Parse(Console.ReadLine());
                      Array2.Add(amount);
                      Console.WriteLine("***Stock Sold***");
                      break;
  
  
                  case "0":
                      Console.WriteLine("Good Bye!");
                      return;
  
                  default:
                      message = "Invalid entry";
                      break;
  
              }
  
              Console.Write(message);
              Console.ReadLine();
              Console.WriteLine();
  
  
          } //while (userValue != "0");  
      }
  }
  }
  </code></pre>