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

No boxing with string concat in VS2019 #81

Open
sonnemaf opened this issue Jan 10, 2020 · 1 comment
Open

No boxing with string concat in VS2019 #81

sonnemaf opened this issue Jan 10, 2020 · 1 comment

Comments

@sonnemaf
Copy link

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.

@cezarypiatek
Copy link
Contributor

This kind of problem has been discussed in #8

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants