문자열이 −
라고 가정해 보겠습니다.string str = "3456";
이제 입력한 문자열이 숫자인지 확인하려면 -
str.All(c => char.IsDigit(c))
위는 문자열이 숫자이면 true를 반환하고 그렇지 않으면 false를 반환합니다.
다음은 전체 코드입니다 -
예시
using System;
using System.Linq;
namespace Demo {
public class MyApplication {
public static void Main(string[] args) {
string str = "3456";
// checking if string is a number or not
Console.WriteLine(str.All(c => char.IsDigit(c)));
}
}
} 출력
True