투케이2K

67. (C#/NET) [Mac Os] [문법] enum 열거체 선언 및 IsDefined 사용해 문자열 존재 여부 확인 본문

C샵 (NET)

67. (C#/NET) [Mac Os] [문법] enum 열거체 선언 및 IsDefined 사용해 문자열 존재 여부 확인

투케이2K 2024. 3. 17. 09:34
반응형

[개발 환경 설정]

개발 언어 : C# / NET

 

[소스 코드]

 

using System;
using System.Collections;
using System.Data;
using System.Diagnostics.Tracing;
using System.Text;
using System.Web;

namespace testProject {


    // [프로그램 동작 클래스]
    class Program {


        // [enum 선언]
        enum Response { None = 1, Success = 2, Fail = 3 }


        // [메소드 수행]
        static void Main(string[] args){

            // [변수 선언 실시] : [IsDefined 문자열 존재 값 확인]
            bool isSuccess = Response.IsDefined(typeof(Response), "Success");
            bool isError = Response.IsDefined(typeof(Response), "Error");


            // [로그 출력 수행]
            Console.WriteLine($"");
            Console.WriteLine($"------------------------------------------");
            Console.WriteLine($"[Main] : [Log]");
            Console.WriteLine($"------------------------------------------");
            Console.WriteLine($"isSuccess : {isSuccess}");
            Console.WriteLine($"------------------------------------------");
            Console.WriteLine($"isError : {isError}");
            Console.WriteLine($"------------------------------------------");
            Console.WriteLine($"");

        }

    }

}
 

[결과 출력]

 

 

반응형
Comments