Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

int.ToString() error on string concatenation Visual Studio 2019

After i updated my Visual Studio 2019 from v16.2.5 to v16.3.5 some errors occured in my application in every place where i use string concatenation.

Ex:

int x = 5;
string y = x + " years";

What has changed? How does the Culture influences int? enter image description here

like image 862
Marius Vuscan Avatar asked Dec 10 '25 12:12

Marius Vuscan


2 Answers

I think you might have ticked the treat warnings as errors radio button.

An int can be displayed in western digits (0, 1, 2, 3, ... 9) or it can be displayed in other digits such as Arabic (٠ ١ ٢ ٣) or Thai (๑ ๒ ๓) and so on.

Therefor, an int representation is culture dependent, and hence the error.

For more information, check out official documentation.

like image 199
Zohar Peled Avatar answered Dec 12 '25 03:12

Zohar Peled


This message stems from the code analysis feature of Visual Studio. For more info regarding this specific warning, see the documentation. There it says:

[...] .NET members choose default culture and formatting based on assumptions that might not be correct for your code. To make sure that the code works as expected for your scenarios, you should supply culture-specific information according to the following guidelines: [...]

It's generally good practice to be mindful of .ToString calls that end up being show to the user.

like image 31
germi Avatar answered Dec 12 '25 01:12

germi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!