decimal? type is not culture specific

I was converting a decimal to a string , using the following lines of code:

decimal a = 0;
a.ToString();

and Resharper gave me the following warning: "Specify string culture explicity". I guess this makes sense, since some cultures may use a "." (dot) or a "," (comma) as a decimal mark.

However, the following lines of code:

decimal? a = 0; //a is now nullable
a.ToString();

do not present the same warning. I was wondering if this is a bug in Resharper, or is there something special about a nullable decimal ?


To extend upon Gama Felix's answer, I would assume that this is because decimal?.ToString() does not have overloads which would accept a culture. If you don't care about culture specific strings, then you're set. If you do care, then you should check for a value and use decimal?.Value.ToString() .


I believe that it happens because decimal? is just a alias to Nulable<decimal> , so you are calling the ToString() method on the nullable class not the decimal type.

链接地址: http://www.djcxy.com/p/75104.html

上一篇: CultureInfo.InvariantCulture和DateTime如何工作

下一篇: 十进制? 类型不是文化特定的