Difference between resharper and C# compiler

I have a source file with code like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Test
{
     class Class1
     {
          private IntPtr _ptr = (IntPtr) null;
     }
}

R# says its an error, but this code compiles without a warning on VS2008. 
IntPtr is a struct, so I think it cannot be set to null. Only thing is, 
the code seems to work ;)

Since R# should follow the compiler I think its a bug in R#.

Regards,

Arnold Nelisse

2 comments
Comment actions Permalink

Arnold,

IntPtr is a struct, so I think it cannot be set to null. Only thing is, 
the code seems to work ;)


Of course it cannot be set to null but by using "(IntPtr)" cast you are
calling an operator (from IL disassembly):

  public static unsafe explicit operator IntPtr(void* value)

But now the strange thing is that it's calling an unsafe method without
raising a warning/error for this.

Since Reflector is disassembling this into "_ptr = IntPtr.Zero" I guess
there are some C# specific rules acting against IntPtr and hiding
internals.

--
/\/\arkus.

0
Comment actions Permalink

Op Thu, 08 Dec 2011 16:35:24 +0100 schreef Markus Springweiler 
<springy@gmx.de>:

Arnold,

>
>> IntPtr is a struct, so I think it cannot be set to null. Only thing is,
>> the code seems to work ;)
>

Of course it cannot be set to null but by using "(IntPtr)" cast you are
calling an operator (from IL disassembly):

>

  public static unsafe explicit operator IntPtr(void* value)

>

But now the strange thing is that it's calling an unsafe method without
raising a warning/error for this.

>

Since Reflector is disassembling this into "_ptr = IntPtr.Zero" I guess
there are some C# specific rules acting against IntPtr and hiding
internals.

>

Sounds like a logical explanation. Can R# be made aware of this situation 
so I don't get a lot of errors in my solution?

0

Please sign in to leave a comment.