编程语言
首页 > 编程语言> > C++与C#中枚举的区别

C++与C#中枚举的区别

作者:互联网

一、C++

#include <iostream>
using namespace std;
enum week{Monday,Thuesday};
int main()
{
    week day;
    day = Monday;
    day = Thuesday;
    //day = 4;  报错 类型转化出错
    //day++;   出错,没有++ 操作
    cout << day << endl;//输出结果为1
    return 0;
}

二、C#

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

namespace myEnum_Structure
{
    enum Week
    {
        Monday,
        Thuesday,
        Wednesday,
        Thursday,
        Friday,
        Saturday,
        Sunday
    }
    class Program
    {
        static void Main(string[] args)
        {
            Week day;
            day = Week.Sunday;
            Console.WriteLine(day);//输出Sunday
            day++;
            Console.WriteLine(day);//输出7
        }
    }
}

标签:Thuesday,C#,Sunday,System,C++,++,枚举,using,day
来源: https://www.cnblogs.com/wml-it/p/15763929.html