zoukankan      html  css  js  c++  java
  • c# 枚举操作 正运算 逆运算

    没用控制台写,用WPF写的例子

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Shapes;
    
    
    namespace WpfDemoNew
    {
        /// <summary>
        /// Window23.xaml 的交互逻辑
        /// </summary>
        public partial class Window23 : Window
        {
            public Window23()
            {
                InitializeComponent();
    
                TimeOfDay time = TimeOfDay.Afternoon;
    
                MessageBox.Show(Convert.ToInt32(time).ToString());//根据枚举值,取对应的索引值,输出Afternoon的索引值1
                MessageBox.Show(TimeOfDay.Afternoon.ToString());//输出Afternoon
    
                time = (TimeOfDay)Enum.Parse(typeof(TimeOfDay), "2",true);//忽略大小写匹配,根据索引值取值
    
                MessageBox.Show(time.ToString()); //输出Evening
    
                time = (TimeOfDay)Enum.Parse(typeof(TimeOfDay), "Evening", true);//忽略大小写匹配,根据值取值
    
                MessageBox.Show(time.ToString()); //输出Evening
    
                time = (TimeOfDay)Enum.Parse(typeof(TimeOfDay), "12", true);//忽略大小写匹配,根据索引值取值
    
                MessageBox.Show(time.ToString()); //超出TimeOfDay的最大索引值,输出12
    
                MessageBox.Show(Enum.GetName(typeof(TimeOfDay), 1)); //根据索引值取值,输出Afternoon
                //MessageBox.Show(Enum.GetName(typeof(TimeOfDay), "Afternoon")); //根据值取值,不支持报错.
                MessageBox.Show(Enum.GetName(typeof(TimeOfDay), 10)); //超出TimeOfDay的最大索引值,输出空字符串
    
            }
    
            public enum TimeOfDay
            {
                Moning = 0,
                Afternoon = 1,
                Evening = 2
            }
        }
    }
  • 相关阅读:
    Mysql 重做日志及与二进制日志的区别
    【MySql】性能优化之分析命令
    ubuntu一些基本软件安装方法
    Linux学习笔记
    exp/imp三种模式——完全、用户、表
    Oracle学习日志20150302
    如何在macOS Sierra中运行CORE Keygen破解程序
    国内各大互联网公司技术站点集合
    React Native资料
    React Native集成到现有项目(非cocoa pods)
  • 原文地址:https://www.cnblogs.com/lanymy/p/2595315.html
Copyright © 2011-2022 走看看