using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
}
}
}
namespace Rectangular
{
public class class1
{
double width,height;
public Rectangular(double width, double height) //这行提示有错
{
this.width = width;
this.height = height;
}
public double GetArea()
{
return width*height;
}
}
}
大神求助问题出在哪里,这是我照书上抄的呢,最近在自学。
错误提示:方法必须具有返回类型
1 问题出在构造函数名和类名不一致
在C#中构造函数名必须和类名一样
修改后的代码如下:
using System;2 分析
在C#中一般的方法必须具有返回类型,但构造函数除外
3 扩展
在C#中,类名采用PascalCase的形式
class1 显然不符合这一点,应写作Class1