C#枚举-枚举器定义困难
本文关键字:枚举 定义 | 更新日期: 2023-09-27 18:29:55
我正试图从本教程中学习C#:http://rbwhitaker.wikidot.com/c-sharp-enumerations
它建议定义"今天",如下所示,但当我这样做时,我会得到这个错误:'EnumerationTutorial.DaysOfWeek' does not contain a definition for 'today'
我尝试过很多不同的事情,但我不明白我做错了什么。
谢谢你的帮助。
https://i.stack.imgur.com/gi4wB.png
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.IO;
using System.Net;
namespace EnumerationTutorial
{
public enum DaysOfWeek { Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday };
public class Program
{
static void Main(string[] args)
{
DaysOfWeek today = DaysOfWeek.Sunday;
Console.WriteLine(DaysOfWeek.today);
Console.ReadLine();
}
}
}
这声明了一个名为today 的DaysOfWeek类型的变量
DaysOfWeek today = DaysOfWeek.Sunday;
这访问DaysOfWeek的today成员,该成员不存在
Console.WriteLine(DaysOfWeek.today);
试试这个
Console.WriteLine(today);