Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

No boxing with string concat in VS2019 #81

@sonnemaf

Description

@sonnemaf

Suppose you write the following code

using System;

namespace BoxingDemo {
    class Program {
        static void Main(string[] args) {
            
            double salary = 1200;
            string text = "Salary " + salary;
            
            Console.WriteLine(text);
        }
    }
}

You get a warning that there is boxing on line 8, see screenshot.
image

This warning is correct if you compile your code in Visual Studio 2017. But the compiler has changed in 2019. I examined the IL code in SharpLab,io and you don't get any boxing any more. The value type is first converted to a string using ToString() (IL line 12) and then concatenated (IL line 17).

image

I think this warning is in Visual Studio 2019 incorrect.

BTW: I love the tool.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions