You can use the Enum.TryParse()
method to convert a string to the equivalent enumerated value (assuming it exists):
Name myName;
if (Enum.TryParse(nameString, out myName))
{
switch (myName) { case John: ... }
}
More Related Contents:
- How to loop through all enum values in C#? [duplicate]
- Why is a Dictionary “not ordered”?
- How can I automatically filter out soft deleted entities with Entity Framework?
- When should TaskCompletionSource be used?
- Best way to read a large file into a byte array in C#?
- Return StreamReader to Beginning
- Why use the C# class System.Random at all instead of System.Security.Cryptography.RandomNumberGenerator?
- MVVM in WPF – How to alert ViewModel of changes in Model… or should I?
- Am I misunderstanding LINQ to SQL .AsEnumerable()?
- When is optimization premature? [closed]
- Insert into C# with SQLCommand
- Class with indexer and property named “Item”
- Can the C# interactive window interact with my code?
- Select either a file or folder from the same dialog in .NET
- How to suppress a dialog box displayed by code that I can’t change?
- How do I do logging in C# without using 3rd party libraries? [closed]
- Serializing null in JSON.NET
- i have to access/commit/update SVN repository in WPF application using SVN API or libraries [closed]
- Image.Save() throws exception “Value cannot be null./r/nParameter name: encoder”
- Hosting ASP.NET Core API in a Windows Forms Application
- How to stop Windows service programmatically
- Last and LastOrDefault not supported
- How to make a button appear as if it is pressed?
- Is it possible to create some IGrouping object
- Condition Variables C#/.NET
- How to exit all running threads?
- .indexOf for multiple results
- Is TLS 1.1 and TLS 1.2 enabled by default for .NET 4.5 and .NET 4.5.1?
- How do I atomically swap 2 ints in C#?
- Validating user input / Give .NET controls status OK or NOK