2014-01-11 22 views
-3

我開始學習C#在線,我一直在關注教程,但是我的Hello World程序是唯一成功編譯的程序。我無法在C#中編譯

using System; 
namespace HelloWorldApplication 
{ 
    class HelloWorld 
    { 
     static void Main(string[] args) 
     { 
      /* My first program in C# */ 
      Console.WriteLine("Hello World"); 
      Console.ReadKey(); 
     } 
    } 
} 

但是,每當我嘗試編譯任何其他程序,命令窗口的幾分之一秒打開關閉之前並沒有任何反應,程序不能編譯。

using Sytem; 
namespace RectangleApplication 
{ 
    class Rectangle 
    { 
     // Member Variables 
     double length; 
     double width; 
     public void Acceptdetails() 
     { 
      length = 4.5; 
      width = 3.5; 
     } 
     public double GetArea() 
     { 
      return length * width; 
     } 
     public void Display() 
     { 
      Console.WriteLine("Length: {0}", length); 
      Console.WriteLine("Width: {0}", width); 
      Console.WriteLine("Area: {0}", GetArea()); 
      } 
     } 

     class ExecuteRectangle 
     { 
      static void Main(string[] args) 
      { 
       Rectangle r = new Rectangle(); 
       r.Acceptdetails(); 
       r.Display(); 
       Console.Readline(); 
      } 
     } 
    } 
} 

我沒有VisualStudio的,我不能獲得將我的系統上運行的副本(如2005年,2008年),我的Windows XP(Service Pack 2中)。我使用的是Notepad ++和.NET 3.5編譯器。

代碼有什麼問題嗎?

其他人:

using System; 
namespace Tutorial1 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      double x, y; 
      x = 30.0; 
      y = 3.5; 
      console.WriteLine(x%y); 
      console.ReadKey(); 
     } 
    } 
} 
+0

請給出錯誤信息。代碼不僅不能編譯,它不能編譯出於一個非常具體的原因,編譯錯誤會告訴你。它甚至會告訴你哪一行代碼無法編譯。什麼是編譯錯誤? –

+0

從命令行運行你的程序。讓自己一個體面的IDE - MonoDevelop是免費的,可能與XP一起工作。 – zmbq

+2

在Display()方法中是一個冗餘括號。 – Andy

回答

1

你把你的Main方法用錯了地方。此外,您輸入了拼寫錯誤(System,而不是Sytem),並記住C#區分大小寫(WriteLineReadLine而不是WritelineReadline)。試試這個:

using System; 
namespace RectangleApplication 
{ 
    class Rectangle 
    { 
     // Member Variables 
     double length; 
     double width; 
     public void Acceptdetails() 
     { 
      length = 4.5; 
      width = 3.5; 
     } 
     public double GetArea() 
     { 
      return length * width; 
     } 
     public void Display() 
     { 
      Console.WriteLine("Length: {0}", length); 
      Console.WriteLine("Width: {0}", width); 
      Console.WriteLine("Area: {0}", GetArea()); 
     } 
    } 

    class ExecuteRectangle 
    { 
     static void Main(string[] args) 
     { 
      Rectangle r = new Rectangle(); 
      r.Acceptdetails(); 
      r.Display(); 
      Console.ReadLine(); 
     } 
    } 
} 
+2

這不是唯一的問題。請參閱'Display'方法中的懸掛大括號? –

+0

當然,刪除它 - 謝謝! – PiotrK