[Dart] Enum > Node/Flutter/Dart

본문 바로가기
사이트 내 전체검색

Node/Flutter/Dart

[Dart] Enum

페이지 정보

작성자 sbLAB 댓글 0건 조회 2,592회 작성일 23-02-07 22:58

본문

Dart Enum


 
  //Direction Enum
  enum Direction { North, South, East, West }

  //ResultEnum
  enum ResultEnum {
    failed(0),
    pending(1),
    completed(2); //;

    final int status;
    const ResultEnum(this.status);
  }

  main() {
    //Direction Enum
    Direction dir = Direction.South;  //South
    switch (dir) {
      case Direction.North:
        print("North");
        break;
      case Direction.South:
        print("South");
        break;
      case Direction.West:
        print("West");
        break;
      case Direction.East:
        print("East");
        break;
    }

  dir=Direction.North;
  if(dir==Direction.North){
   print("Direction.North!"); //Direction.North!
  }

  var dirIndex=1;
    if (dirIndex == Direction.South.index) {
      print("${Direction.South.index} - dirIndex South!"); //1 - dirIndex South!
    }


  //ResultEnum
    ResultEnum result = ResultEnum.failed; //failed
    switch (result) {
      case ResultEnum.failed:
        print("failed");
        break;
      case ResultEnum.pending:
        print("pending");
        break;
      case ResultEnum.completed:
        print("completed");
        break;
    }

    //ResultEnum - int(status)
    var resultInt = 2;
    if (resultInt == ResultEnum.completed.status) {
      print("${ResultEnum.completed.status} - resultInt completed!"); //2 - resultInt completed!
    }

    //ResultEnum - int(index)
    var resultIndex = 2;
    if (resultIndex == ResultEnum.completed.index) {
      print("${ResultEnum.completed.index} - resultIndex completed!"); //2 - resultIndex completed!
    }
  }

  //South
//Direction.North!
  //1 - dirIndex South!
  //failed
  //2 - resultInt completed!
  //2 - resultIndex completed!

 


https://www.darttutorial.org/dart-tutorial/dart-enum/ 


댓글목록

등록된 댓글이 없습니다.

회원로그인

접속자집계

오늘
109
어제
190
최대
1,279
전체
232,730

그누보드5
Copyright © sebom.com All rights reserved.