소프트웨어 개발(SW Dev)/C#
IDE0018 (Variable declaration can be inlined)
flowhistory
2020. 6. 15. 12:06
변수 선언은 인라인할 수 있습니다.
int result;
if (int.TryParse(input, out result))
Console.WriteLine(result);
else
Console.WriteLine("Could not parse input");
매개 변수를 지원하는 기존 구문이 C# 7.0 버전에서 개선 되어서 별도의 선언문을 작성하지 않고 메소드 호출의 인수 목록에서 변수를 선언할 수 있게 되었다.
코드를 다음과 같이 수정한다.
//int result;
if (int.TryParse(input, out int result))
Console.WriteLine(result);
else
Console.WriteLine("Could not parse input");
728x90