title: object reference not set to an instance of an object console.readline.tolower
body: <p>I am having the hardest time trying to fix this code. Any and all help is greatly appreciated. Before I start debugging, there are no red underlines or anything. But when I hit debug, this line of code <code>hitOrStay = Console.ReadLine().ToLower().;</code> gets the following error: "object reference not set to an instance of an object"</p>
  
  <p>Here is my source code:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Linq;
  using System.Text;
  using System.Windows.Forms;
  
  namespace finalBlackjack
  {
  public partial class Form1 : Form
  {
      public Form1()
      {
          InitializeComponent();
      }
  
      static string[] playerCards = new string[12];
      static string hitOrStay = "";
      static int total = 0, count = 1, dealerTotal = 0;
      static Random cardRandomizer = new Random();
  
      static void Start()
      {
          dealerTotal = cardRandomizer.Next(15, 22);
          playerCards[0] = Deal();
          playerCards[1] = Deal();
          do
          {
              Console.WriteLine("Welcome to Blackjack! You were dealed " + playerCards[0] + " and " + playerCards[1] + ". \nYour total is " + total + ".\nWould you like to hit or stay?");
              hitOrStay = Console.ReadLine().ToLower();
  
          } while (!hitOrStay.Equals("hit") &amp;&amp; !hitOrStay.Equals("stay"));
          Game();
      }
  
      static void Game()
      {
          if (hitOrStay.Equals("hit"))
          {
              Hit();
          }
          else if (hitOrStay.Equals("stay"))
          {
              if (total &gt; dealerTotal &amp;&amp; total &lt;= 21)
              {
                  Console.WriteLine("\nCongrats! You won the game! The dealer's total was " + dealerTotal + ".\nWould you like to play again? y/n");
                  PlayAgain();
              }
              else if (total &lt; dealerTotal)
              {
                  Console.WriteLine("\nSorry, you lost! The dealer's total was " + dealerTotal + ".\nWould you like to play again? y/n");
                  PlayAgain();
              }
  
          }
          Console.ReadLine();
      }
  
      static string Deal()
      {
          string Card = "";
          int cards = cardRandomizer.Next(1, 14);
          switch (cards)
          {
              case 1: Card = "Two"; total += 2;
                  break;
              case 2: Card = "Three"; total += 3;
                  break;
              case 3: Card = "Four"; total += 4;
                  break;
              case 4: Card = "Five"; total += 5;
                  break;
              case 5: Card = "Six"; total += 6;
                  break;
              case 6: Card = "Seven"; total += 7;
                  break;
              case 7: Card = "Eight"; total += 8;
                  break;
              case 8: Card = "Nine"; total += 9;
                  break;
              case 9: Card = "Ten"; total += 10;
                  break;
              case 10: Card = "Jack"; total += 10;
                  break;
              case 11: Card = "Queen"; total += 10;
                  break;
              case 12: Card = "King"; total += 10;
                  break;
              case 13: Card = "Ace"; total += 11;
                  break;
              default: Card = "2"; total += 2;
                  break;
          }
          return Card;
      }
  
      static void Main()
      {
          Start();
      }
  
      static void Hit()
      {
          count += 1;
          playerCards[count] = Deal();
          Console.WriteLine("\nYou were dealed a(n) " + playerCards[count] + ".\nYour new total is " + total + ".");
          if (total.Equals(21))
          {
              Console.WriteLine("\nYou got Blackjack! The dealer's total was " + dealerTotal + ".\nWould you like to play again?");
              PlayAgain();
          }
          else if (total &gt; 21)
          {
              Console.WriteLine("\nYou busted, therefore you lost. Sorry. The dealer's total was " + dealerTotal + ".\nWould you like to play again? y/n");
              PlayAgain();
          }
          else if (total &lt; 21)
          {
              do
              {
                  Console.WriteLine("\nWould you like to hit or stay?");
                  hitOrStay = Console.ReadLine().ToLower();
              } while (!hitOrStay.Equals("hit") &amp;&amp; !hitOrStay.Equals("stay"));
              Game();
          }
      }
  
      static void PlayAgain()
      {
          string playAgain = "";
          do
          {
              playAgain = Console.ReadLine().ToLower();
          } while (!playAgain.Equals("y") &amp;&amp; !playAgain.Equals("n"));
          if (playAgain.Equals("y"))
          {
              Console.WriteLine("\nPress enter to restart the game!");
              Console.ReadLine();
              Console.Clear();
              dealerTotal = 0;
              count = 1;
              total = 0;
              Start();
          }
          else if (playAgain.Equals("n"))
          {
              Console.WriteLine("\nPress enter to close Blackjack.");
              Console.ReadLine();
              Environment.Exit(0);
          }
  
      }
  }
  }
  </code></pre>