'The type or namespace name 'Parse' does not exist in the namespace 'Enum'
I have System in my namespace, what am I missing? I am brand new to C# and am following a course on Udemy and following a book titled C#8.0 and .NET Core 3.0 - any other materials that people recommend would be really useful.
The problem is arising from 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);
}
}
}
Solution 1:[1]
I had to change it to System.Enum.Parse - odd, because I have using System; in the file.
Solution 2:[2]
You have to check your namespace to not be {{Your solution name}}.Enum
Solution 3:[3]
namespace Enum_1
{
public enum ShippingMethod
{
RegularMail = 1,
Registered = 2,
Express = 3
}
Change the namespace Enum, something like Enum_1
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | TomFp |
Solution 2 | wtrtrkl |
Solution 3 | Lha |