Skip to content

VS shows cast to (ulong) as reduncant when its not #31303

@vsfeedback

Description

@vsfeedback

Consider the following C# code:

    static void CheckRedundantCast()
    {
        ulong number1 = 0xFFFFFFFFFFFFFFFFL;
        uint number2 = 0xFF;
        ulong myResult = number1 & ~(ulong)number2;

        Console.WriteLine(myResult.ToString("X16"));
    }

Here, VS 15.9 will show that the "(ulong)" cast before number2 is redundant. However, actually it's not redundant, because when you remove it, the output when running the program will change from:

FFFFFFFFFFFFFF00

to:

00000000FFFFFF00

Thanks!

This issue has been moved from https://developercommunity.visualstudio.com/content/problem/385829/vs-shows-cast-to-ulong-as-reduncant-when-its-not.html
VSTS ticketId: 731917

These are the original issue comments:
(no comments)
These are the original issue solutions:
(no solutions)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-IDEBugDeveloper CommunityThe issue was originally reported on https://developercommunity.visualstudio.comhelp wantedThe issue is "up for grabs" - add a comment if you are interested in working on it

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions