아래 코드에서 Resharper 나에게 경고 : Cannot cast expression of type 'Color' to type 'UIntPtr'
을 제공합니다. (사실, Resharper는 실제 오류라고 생각합니다.)Resharper 경고 캐스팅 열거 형 UIntPtr 수 있지만 컴파일러 경고가
그러나 컴파일러 경고가 없으므로 정상적으로 작동합니다.
이것은 Resharper 버그와 같습니다. 그렇지? 아니면 컴파일러가 걱정하지 않는 나쁜 점이 있습니까?
using System;
namespace Demo
{
internal class Program
{
public enum Color { Red, Green, Blue }
private static void Main(string[] args)
{
UIntPtr test = (UIntPtr) Color.Red; // Resharper warning, no compile warning.
}
}
}
내가 경고가 먼저 int로 값을 주조로 사라 할 수 있습니다 (내가 ReSharper에서 7.1.1를 사용하고 있습니다) 그래서 해결 방법이 있습니다
UIntPtr test = (UIntPtr)(int) Color.Red;
resharpers 문제는 런타임에 실패하거나 플랫폼간에 예기치 않게 작동하는 것입니다. –
64 비트 시스템에서도 문제가 발생할 수 있습니다. – alzaimar
@alzaimar 어떻게? 이유를 볼 수 없습니다 ... –