Skip to content

IDE0004 false positive when casting int litral to nint and trying to assign to IntPtr #64825

Closed as not planned
@Tan90909090

Description

Version Used:
Microsoft Visual Studio Community 2022 (64-bit) - Current
Version 17.3.6

Steps to Reproduce:

  1. Set <LangVersion>10.0</LangVersion> in csproj.
  2. Write a following code:
System.IntPtr x = (nint)1;

Expected Behavior:
There is no IDE0004.

Actual Behavior:
There is an IDE0004 Cast is redundant on (nint).
If I remove the cast then I get an error: CS0266 Cannot implicitly convert type 'int' to 'System.IntPtr'. An explicit conversion exists (are you missing a cast?)

Note: The cast may be really redundant when using C# 11 because there is a new feature "numeric IntPtr".

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions