c#学习1、声明一个矩形结构,计算面积

    科技2025-09-22  82

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

    namespace ConsoleApplication2 { class Program { struct Rect { public double Width; public double Height;

    public double Area() { return Width * Height; } } static void Main(string[] args) { Rect MyRect; MyRect.Height = 100; MyRect.Width = 200; Console.WriteLine("MyRect Height:{0}", MyRect.Height); Console.WriteLine("MyRect Width:{0}", MyRect.Width); Console.WriteLine("矩形面积={0}", Area); Console.ReadLine(); } }

    } 写的代码,但是总是提示 错误 CS0103 当前上下文中不存在名称“Area”

    也不知道什么问题, 借用了别人写的代码进行测试 C#基本语法-实现在控制台输出矩形的长宽面积 https://blog.csdn.net/ljyyoo/article/details/68490722?utm_medium=distribute.pc_relevant_ask_down.none-task-blog-baidujs-1.nonecase&depth_1-utm_source=distribute.pc_relevant_ask_down.none-task-blog-baidujs-1.nonecase 还是提示 错误 CS0103 当前上下文中不存在名称“Area”

    先把问题留下来,继续学习吧

    Processed: 0.009, SQL: 8