Computer >> 컴퓨터 >  >> 프로그램 작성 >> C#

C#의 ArgumentNullException


null 참조가 유효한 인수로 허용되지 않는 메서드에 전달되면 예외가 발생합니다.

예를 들어 보겠습니다.

null 매개변수를 int.Parse() 메서드로 설정하면 ArgumentNullException이 아래와 같이 발생합니다. -

예시

using System;
class Demo {
   static void Main() {
      string val = null;
      int res = int.Parse(val); // error is thrown
   }
}

출력

null 값을 전달했기 때문에 위의 프로그램을 컴파일할 때 다음 오류가 발생합니다.

Unhandled Exception:
System.ArgumentNullException: Value cannot be null.