.net(基本数据类型,枚举类型,枚举字符串的相互转化)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication3
{
    /// <summary>
    /// 
    /// </summary>
    
    class Program
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            Cat cat = new Cat();
            cat.name = "Jerry";
            cat.color = "Red";

            Cat homeCat = new Cat();

            homeCat.name = cat.name;
            homeCat.color = cat.color;

            homeCat.name = "Tom";
            cat.color = "Green";

            // readonly const区别?

            // 枚举类型 ---〉基本类型
            Direction dir = Direction.UP;
            Console.WriteLine((int)dir);

            // 基本类型 ---〉枚举类型
            int underlyingType = 2;
            Direction enumType =(Direction)Enum.Parse(typeof(Direction), underlyingType.ToString());

            // 基本类型 ---〉枚举字符串
            int underlyingTypeString = 3;
            string enumString = Enum.GetName(typeof(Direction), underlyingTypeString);

        }
    }

    /// <summary>
    /// 
    /// </summary>
    public class Cat
    {
        /// <summary>
        /// 
        /// </summary>
        public string name
        {
            get;
            set;
        }

        /// <summary>
        /// 
        /// </summary>
        public string color
        {
            get;
            set;
        }
    }

    enum Direction
    {
        UP, DOWN, LEFT, RIFHT
    }
}

posted on 2012-07-10 09:06  Yours风之恋  阅读(468)  评论(0编辑  收藏  举报