在下面的代码中,Resharper 给我一个警告:Cannot cast expression of type 'Color' to type 'UIntPtr'
。 (实际上,Resharper 认为这是一个实际错误。)
但是,没有编译器警告,它工作正常。
在我看来,这像是一个 Resharper 错误。是吗?还是编译器不担心它有什么不好的地方? (我使用的是 Resharper 7.1.1)
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 来使警告消失,所以我有一个解决方法:
UIntPtr test = (UIntPtr)(int) Color.Red;
最佳答案
This looks like a Resharper bug to me. Is it?
Yes :
RSRP-78748 False 'conversion does not exist' (UIntPtr)
using System; class A { static void Main() { E? x = 0; UIntPtr z = (UIntPtr)x; } } enum E { }
It is a known spec devation.
截至 2013 年 3 月 5 日尚未修复。
关于c# - Resharper 警告将枚举转换为 UIntPtr,但没有编译器警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15222343/