我的命名空间中有System,我遗漏了什么?我是一个全新的C#新手,正在学习一门关于Udemy的课程,并且正在阅读一本名为“C#8.0和.NET Core3.0”的书--人们推荐的任何其他资料都会非常有用。
问题是由Enum.Parse引起的
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Enum
{
public enum ShippingMethod
{
RegularMail = 1,
Registered = 2,
Express = 3
}
class Program
{
static void Main(string[] args)
{
var method = ShippingMethod.Express;
Console.WriteLine((int)method);
var methodId = 3;
Console.WriteLine((ShippingMethod)methodId);
Console.WriteLine(method.ToString());
//Here we take a string and convert it a enum
var methodName = "Express";
//We will have to "parse" the string to a different type
var shippingMethod = (ShippingMethod)Enum.Parse(typeof(ShippingMethod), methodName);
}
}
}发布于 2021-02-10 21:23:38
我必须将其更改为System.Enum.Parse - odd,因为我在文件中使用了System;。
https://stackoverflow.com/questions/66128592
复制相似问题