2014-02-28 37 views
0

我需要幫助像C#錯誤消息

錯誤17「的GetInfo」這個名字不會在目前情況下」和 錯誤15只分配存在搞清楚我得到(新秀),不同的錯誤信息,打電話,遞增,遞減和新對象 表達式可以作爲一份聲明中

我的代碼:

studentNumber = GetInfo("student identification number"); 
secondScore = GetInfo("second test score"); 

你有什麼需要看到幫我破譯這些錯誤

這裏是我的代碼:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 

namespace ConsoleApplication1 
{ 
    class Program2 
    { 
     static void Main(string[] args) 
     { 
      int studentNumber; 
      firstScore; 
      secondScore; 
      thirdScore; 
      DisplayInstructions(); 

      studentNumber = GetInfo("student identification number"); 

      Console.WriteLine(); 

      firstScore = GetInfo("first test score"); 
      thirdScore = GetInfo("third test score"); 

     } 

     public static void DisplayInstructions(); 
     { 

      Console.WriteLine("\tGrading Application\n"); 

      Console.WriteLine("You will Be asked to enter a student ID number "); 

      Console.WriteLine("and three test scores."); 

      Console.WriteLine("This information and the average exam score "); 

      Console.WriteLine("will be displayed.\n\n"); 

      Console.WriteLine("Press any key to begin..."); 

      Console.ReadKey(); 

      Console.Clear(); 

     } 


     public static int GetInfo(string info); 
     { 

      string inputValue; 
      int number; 

      Console.Write("Please enter the {0}: ", info); 

      inputValue = Console.ReadLine(); 

      number = int.Parse(inputValue); 

      return number 
     } 
    } 
} 
+0

試想什麼是獲取信息和你是如何獲得它 – Rex

+1

什麼是'GetInfo()'?你能告訴我們完整的代碼嗎? –

+2

爲什麼downvote的人清楚地試圖學習 – blizz

回答

2

我的理論將是沒有定義的GetInfo方法,或者是有編譯錯誤是getinfo方法,導致它不會被其他代碼看到。

0

錯誤本身正在給出答案,因爲錯誤指出'GetInfo'在當前上下文中不存在',這意味着GetInfo()在當前文檔中不存在。

+0

OP的位置或其他代碼片段可能存在問題,OP沒有發佈。如果只有'GetInfo'沒有被定義,那麼這個錯誤不會被拋出/在作用域中:'錯誤15只有賦值,調用,遞增,遞減和新的對象表達式可以用作語句' –

0

您的代碼有幾個問題。

  1. 不應該有方法名之間的;。它的機身:

    public static void DisplayInstructions(); 
    

    應該是:

    public static void DisplayInstructions() 
    

    public static int GetInfo(string info); 
    

    應該是

    public static int GetInfo(string info) 
    
  2. 你沒有一個數據類型爲firstscoresecondscorethirdscore

    firstScore; 
    secondScore; 
    thirdScore; 
    

    應該是:

    int firstScore; 
    int secondScore; 
    int thirdScore; 
    
  3. 你缺少在該行return number結束分號在GetInfo

+0

是的,我通過試驗和錯誤,現在我已經添加了一些更多的代碼:public static double ExamScoreAverage; const int NUMBER_OF_EXAM_SCORES = 3; 雙考examScoreAverage; double firstScore; double secondScore; double thirdScore; examScoreAverage =(firstScore + secondScore + thirdScore)/ 3; Console.WriteLine(「Exam average」+「is」,examScoreAverage); Console.Read(); } } 並且這些錯誤到達 – user3363232