본문 바로가기
C 언어

C# - 숫자인지 아닌지 판단하기 (int.TryParse)

by DemoMaker 2023. 12. 20.
반응형
반응형

 

        private void btn_TryParse_Click(object sender, EventArgs e)
        {
            string str_Message = "";

            int i = 0;

            string str_Chk = txt_Value.Text;

            bool bol_Result = int.TryParse(str_Chk, out i);

            if (bol_Result)
            {
                str_Message = $"' {str_Chk} ' 은(는) 숫자가 맞습니다.";
            }
            else
            {
                str_Message = $"' {str_Chk} ' 은(는) 숫자가 아닙니다.";
            }

            MessageBox.Show(str_Message);
        }

 

숫자판단 OK
숫자판단 NG

반응형

'C 언어' 카테고리의 다른 글

C언어를 배워보자  (0) 2023.09.25
Python의 역사와 장점과 단점  (0) 2023.09.22
Java의 역사와 장점과 단점  (0) 2023.09.21
C#의 역사와 장점과 단점  (0) 2023.09.20
C++의 역사와 장점과 단점  (0) 2023.09.20

댓글