我是c#的新手(我从1月开始),我正在编写的代码需要帮助。在所有出现错误的行上,它都说
预期的类,委托,枚举,接口或结构
这是我的代码:
using System;
namespace pawlowski_Catherine_Lab3
{
public class Course
{
protected string description;
protected string prefix;
protected double number;
protected double hours;
}
public Course ()
{
this.hours="3.00";
}
public Course(string description, string prefix, double number, double hours)
{
this.description=description;
this.prefix=prefix;
this.number=number;
this.hours=hours;
}
public override string ToString ()
{
return string.Format ("Course: "+prefix+"\nCourse Number: "+number+"\nDescription: "+description+"\nCredit hours: "+hours);
}
}
除了第一个错误以外,几乎所有错误都出现在开头的地方。请帮助我弄清楚我到底在做错什么,以便将来自己解决。
这可能会关闭,因此:
这是您(格式化)的内容:
using System;
namespace pawlowski_Catherine_Lab3 {
public class Course {
protected string description;
protected string prefix;
protected double number;
protected double hours;
}
public Course() {
this.hours = "3.00";
}
public Course(string description, string prefix, double number, double hours) {
this.description = description;
this.prefix = prefix;
this.number = number;
this.hours = hours;
}
public override string ToString() {
return string.Format("Course: " + prefix + "\nCourse Number: " + number + "\nDescription: " + description + "\nCredit hours: " + hours);
}
}
这是您应该拥有的(构造函数和方法是类的一部分):
using System;
namespace pawlowski_Catherine_Lab3 {
public class Course {
protected string description;
protected string prefix;
protected double number;
protected double hours;
public Course() {
this.hours = "3.00";
}
public Course(string description, string prefix, double number, double hours) {
this.description = description;
this.prefix = prefix;
this.number = number;
this.hours = hours;
}
public override string ToString() {
return string.Format("Course: " + prefix + "\nCourse Number: " + number + "\nDescription: " + description + "\nCredit hours: " + hours);
}
}
}
正确的缩进是您的朋友。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句