名称''在当前上下文中不存在
CRN courseid timedays Roomnumber
在显示屏上,没有任何项目被识别。为什么显示器在声明为set并获得时没有看到它们?
using System;
using System.Collections.Generic;
using System.Text;
public class Section
{
private int crn;
private String courseId;
private String timeDays;
private String roomNumber;
private int instructor;
/// <summary>
/// Creates a new instance of a section
/// </summary>
/// <param name="crn"></param>
/// <param name="courseId"></param>
/// <param name="timeDays"></param>
/// <param name="roomNumber"></param>
/// <param name="instructor"></param>
public Section(int crn, string courseId, string timeDays, string roomNumber, int instructor)
:this(crn, courseId, timeDays, roomNumber, instructor, "")
{
}
/// <summary>
/// Creates a new instance of a section
/// </summary>
/// <param name="crn"></param>
/// <param name="courseId"></param>
/// <param name="timeDays"></param>
/// <param name="roomNumber"></param>
/// <param name="instructor"></param>
/// <param name="message"></param>
public Section(int crn, string courseId, string timeDays, string roomNumber, int instructor, string message)
{
this.Crn = crn;
this.CourseId = courseId;
this.TimeDays = timeDays;
this.RoomNumber = roomNumber;
this.Instructor = instructor;
this.Message = message;
}
/// <summary>
/// Gets or sets the crn
/// </summary>
public int Crn { get; set; }
/// <summary>
/// gets or sets the course id
/// </summary>
public string CourseId { get; set; }
/// <summary>
/// gets or sets the time days
/// </summary>
public string TimeDays { get; set; }
/// <summary>
/// gets or sets the room number
/// </summary>
public string RoomNumber { get; set; }
/// <summary>
/// Gets or sets the instructor
/// </summary>
public int Instructor { get; set; }
/// <summary>
/// Gets or sets the message
/// </summary>
public string Message { get; set; }
public void display(){
System.Console.WriteLine("CRN = "+ getCrn());
System.Console.WriteLine("CourseID = "+ getCourseId());
System.Console.WriteLine("Time Days = " + getTimeDays());
System.Console.WriteLine("Room Number = " + getRoomNumber());
}
}
答案 0 :(得分:0)
我认为display()需要如下所示。我不知道你的display()函数是如何编译的。
public void display()
{
System.Console.WriteLine("CRN = "+ Crn);
System.Console.WriteLine("CourseID = "+ CourseId);
System.Console.WriteLine("Time Days = " + TimeDays);
System.Console.WriteLine("Room Number = " + RoomNmber);
}
此外,由于您使用{get;声明了所有属性组; },您不需要任何后备成员变量(编译器会自动为您处理这些变量)。因此,您可以删除如下所示的行:
private int crn;
private String courseId;
private String timeDays;
private String roomNumber;
private int instructor;