Enum.Parse

using System;
using System.Collections.Generic;

namespace test
{
    public enum Color
    {
        Red
    }

    class Program
    {
        static void Main()
        {
            string str = "Red";

            Color newC = (Color)Enum.Parse(typeof(Color), str);
            Console.WriteLine(newC.ToString());

            Console.ReadKey();
        }
    }
}

你可能感兴趣的:(String,Class)