C# 为什么我不能实例化它并调用;计算;方法?

C# 为什么我不能实例化它并调用;计算;方法?,c#,.net,C#,.net,我在这页上看到一个问题 尝试在VS中实现它,以下是我的完整代码: public class TopTalInterviewQuestions { //write code to calculate the circumference of the circle, without modifying the Circle class itself. Circle myCircle = new Circle(); myCircle.??? // here VS does

我在这页上看到一个问题 尝试在VS中实现它,以下是我的完整代码:

 public class TopTalInterviewQuestions
 {
    //write code to calculate the circumference of the circle, without modifying the Circle class itself.
    Circle myCircle = new Circle();
    myCircle.??? // here VS does not help me        
}

public sealed class Circle
{
    //public Circle() { }
    private double radius;
    public double Calculate(Func<double, double> op)
    {
        return op(radius);
    }
}
public class-toptli访谈问题
{
//编写代码来计算圆的周长,而不修改circle类本身。
圆圈myCircle=新圆圈();
myCircle.???//这里VS帮不了我
}
公共封闭类圈
{
//公共圈(){}
私人双半径;
公共双计算(Func op)
{
返回op(半径);
}
}
为什么我不能实例化它并调用“Calculate”方法? 请向初学者解释。

在本课程中:

public class TopTalInterviewQuestions
{
    //write code to calculate the circumference of the circle, without modifying the Circle class itself.
    Circle myCircle = new Circle();
    myCircle.??? // here VS does not help me        
}
当您编写行
myCircle.?
时,您试图将语句直接放在类声明中。你不能那样做;语句需要进入方法内部

试着这样做:

public class TopTalInterviewQuestions
{
    //write code to calculate the circumference of the circle, without modifying the Circle class itself.
    Circle myCircle = new Circle();
    public void MyMethod()
    {
        myCircle.???
    } 
}
在本课程中:

public class TopTalInterviewQuestions
{
    //write code to calculate the circumference of the circle, without modifying the Circle class itself.
    Circle myCircle = new Circle();
    myCircle.??? // here VS does not help me        
}
当您编写行
myCircle.?
时,您试图将语句直接放在类声明中。你不能那样做;语句需要进入方法内部

试着这样做:

public class TopTalInterviewQuestions
{
    //write code to calculate the circumference of the circle, without modifying the Circle class itself.
    Circle myCircle = new Circle();
    public void MyMethod()
    {
        myCircle.???
    } 
}

如图所示的代码工作正常,不知道您的问题是什么。你确定你提供了重现问题的所有信息吗?特别是:您得到了哪个编译器错误?您使用的是哪个版本的VS?在尝试自动完成之前,您是否构建了解决方案?开始时是否启用了“自动完成”?这么多的问题…circle.Calculate(r=>2*Math.PI*r)他们的网站上也有“用解释显示正确答案”…可能是@OndrejSvejdar的重复。他不是问我应该传递什么参数,而是问为什么自动完成不起作用。我怀疑代码如图所示起作用,不知道你的问题是什么。你确定你提供了重现问题的所有信息吗?特别是:您得到了哪个编译器错误?您使用的是哪个版本的VS?在尝试自动完成之前,您是否构建了解决方案?开始时是否启用了“自动完成”?这么多的问题…圈出。计算(r=>2*Math.PI*r)他们的网站上也有“用解释展示正确的答案”…可能是@OndrejSvejdar的复制品他不是问我应该传递什么论点而是为什么自动完成不起作用我怀疑感谢@Tanner Swett,现在对e来说很明显,当我陷入这个问题时,我太累了,无法自己解决。谢谢@Tanner Swett,这对e来说是显而易见的,当我陷入这个问题时,我太累了,无法自己解决。