【发布时间】:2009-04-16 23:40:09
【问题描述】:
我正在处理这个家庭作业项目,但无法理解解释如何正确获取枚举的访问值然后将字符串数组值应用于它的文本。你能帮我理解这个吗?我们使用的文本非常困难,而且对于初学者来说写得不好,所以我在这里有点自己。我已经编写了第一部分,但在访问枚举值和分配方面需要一些帮助,我想我已经接近了,但不明白如何正确获取和设置值。
编写一个名为 MyCourses 的课程,其中包含您当前正在学习的所有课程的枚举。这个枚举应该嵌套在你的 MyCourses 类中。您的班级还应该有一个数组字段,该字段提供每个课程的简短描述(作为字符串)。编写一个索引器,将您枚举的课程之一作为索引并返回课程的字符串描述。
namespace Unit_4_Project
{
public class MyCourses
{
// enumeration that contains an enumeration of all the courses that
// student is currently enrolled in
public enum CourseName
{
IT274_01AU,
CS210_06AU
}
// array field that provides short description for each of classes,
// returns string description of the course
private String[] courseDescription =
{"Intermediate C#: Teaches intermediate elements of C# programming and software design",
"Career Development Strategies: Teaches principles for career progression, resume preparation, and overall self anaylsis"};
// indexer that takes one of the enumerated courses as an index
// and returns the String description of the course
public String this[CourseName index]
{
get
{
if (index == 1)
return courseDescription[0];
else
return courseDescription[1];
}
set
{
if (index == 1)
courseDescription[0] = value;
else
courseDescription[1] = value;
}
}
}
}//end public class MyCourses
【问题讨论】: