title: Finding keyword in product list
body: <p>This is the code to find the product names using keyword. I am getting "Null referrence exception" please resolve this problem. I am getting exception in if statement.</p>
  
  <pre><code> static void Main(string[] args)
          {
              try
              {
                  int n;
                  string[] item = null;
                  string[] productName = new string[6];
                  string word;
                  int i;
                  bool flag = false;
                  Console.WriteLine("enter the no of products");
                  n = Convert.ToInt32(Console.ReadLine());
                  for (i = 0; i &lt; n; i++)
                  {
                      productName[i] = Console.ReadLine();
                  }
                  Console.WriteLine("enter the keyword to search");
                  word = Console.ReadLine();
                  foreach (string item1 in productName)
                  {
                      if (item1.Contains(word)) //NullReferenceException
                      {
                          flag = true;
                          item = item1.Split(' ');
                          Console.WriteLine("item:" + item[0]);
                      }
                  }
  
                  if (!flag)
                  {
                      Console.WriteLine("not found");
                      Console.ReadLine();
                  }
  
              }
              catch (NullReferenceException e)
              {
                  Console.WriteLine(e.Message);
                  Console.ReadLine();
              }
          }
  </code></pre>
  
  <p>is there any other way to code this..?</p>