• 结构和枚举


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

    枚举表示有限数据结合。

    他们都是值类型

    结构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 );
        }
    }
  • 相关阅读:
    1043. 输出PATest(20)
    1042. 字符统计(20)
    1041. 考试座位号(15)
    1040. 有几个PAT(25)
    1035. 插入与归并(25)
    栈:火车进站
    ABC Fennec VS. Snuke
    费解的开关
    最短Hamilton路径
    built?
  • 原文地址:https://www.cnblogs.com/CandiceW/p/4231470.html
Copyright © 2020-2023  润新知