Terry Bockman

Terry Bockman

  • NA
  • 8
  • 4.4k

A simple question of methods

Oct 16 2012 10:54 PM

Hi all,

  I am teaching myself C#, and have a simple problem.  The compiler displays an error message for the code (below).  I have spent hours trying to figure out why it won't compile, and, hope one of you very knowledgeable programmers will tell me what is wrong.

Thank-you in advance, Terry

--------------SOURCE CODE & COMPILER ERROR BELOW----------------

// Line 4

using System;

  public class a_String
  {
     public static void Main()
    {
      string aString;
      string strAdded;
      string firstStr = "ABC";
// L15
      Console.Out.Write("Enter the letter after " + firstStr);
      aString = letter(strAdded);
      Console.Out.WriteLine("You entered the letter " + aString);
     
// L20

    } // end Main

// L24
      public static string letter(string input)
     {
        string theLetter;
        theLetter = Console.ReadLine();
        return theLetter;
     }
  } // end class a_String
// L32

// -----   COMPILER ERRORS   -----
// PassStr.cs(17,24): error CS0165: Use of unassigned local variable 'strAdded'


Answers (4)