2014-11-03 48 views
1
using System; 

//Find the square root of a number for 10 values from user 

class forLoop 
{ 
    static void Main 
    { 

     double x; 

     for(int i=10; i>0 && x>=0; i--) 
     { 


     Console.WriteLine("You have {0} remaining calculations left", i); 
     Console.Write("Please enter a positive number: "); 

     x = double.Parse((Console.ReadLine()); 
     x = Math.Sqrt(x); 

     Console.WriteLine("The square root is {0}", x); 
     Console.WriteLine(""); 
     } 

    Console.WriteLine("You have 0 remaining calculations left"); 

    } 

} 

我需要此C#问题的帮助:为什么错误:“获取或设置访问器预期”出现在编译时?错误CS1014:一个获取或设置访问器预计

+0

其中是该方法的特性的方法与C#导入的表达体的例子? – user3289032 2016-10-26 23:32:14

回答

7

您错过了方法声明中的()。因此,编译器认为在,你声明一个属性(尽管它会再扔有关void类型的错误),一定程度上,而不是方法

// Property 
public int Property 
{ 
    get { return _field; } 
    set { _field = value; } 
} 

// Property, albeit a get-only property 
public int Property => _field; 

// Method 
public int Method() 
{ 
    return _field; 
} 

// Method 
public int Method() => _field; 

UPDATE:由于这是仍在看出,我已经更新了示例值,以更好地反映它们的基础类型,并且包括6

2

在方法声明中需要括号(())。

+0

哎呀,非常感谢Slaks! – tehricefarmer 2014-11-03 01:44:43