zoukankan      html  css  js  c++  java
  • 结构和枚举

    结构可用来表示二维,三维数据。

    枚举表示有限数据结合。

    他们都是值类型

    结构struct 

    using System;
      
    struct Point
    {
        public double x, y;
        public Point(int x, int y) {
            this.x = x;
            this.y = y;
        }
        public double R(){
            return Math.Sqrt(x*x+y*y);
        }
    }
      
    class Test
    {
        static void Main() {
            Point[] points = new Point[100];
            for (int i = 0; i < 100; i++)
                points[i] = new Point(i, i*i);
        }
    }

    枚举 enum

    using System;
    enum LightColor 
    {
        Red,
        Yellow,
        Green
    }
    class TrafficLight
    {
        public static void WhatInfo(LightColor color) {
            switch(color) {
                case LightColor.Red:
                    Console.WriteLine(  "Stop!" );
                    break;
                case LightColor.Yellow:
                    Console.WriteLine(  "Warning!" );
                    break;
                case LightColor.Green:
                    Console.WriteLine(  "Go!" );
                    break;
                default:
                    break;
            }
        }
    }
      
    class Test
    {
        static void Main()
        {
            LightColor c = LightColor.Red;
            Console.WriteLine( c.ToString() );
            TrafficLight.WhatInfo( c );
        }
    }
  • 相关阅读:
    POJ 2349 Arctic Network
    OpenJudge 东方14ACM小组 / 20170123 06:Challenge 3
    OpenJudge 东方14ACM小组 / 20170123 02 岛屿
    Best Coder Lotus and Characters
    洛谷 P 1164 小A点菜
    楼房
    虫食算
    斗地主
    国王游戏
    最优贸易
  • 原文地址:https://www.cnblogs.com/CandiceW/p/4231470.html
Copyright © 2011-2022 走看看