Home > Coding Helpers > Code Providers – Convert to Integer

Code Providers – Convert to Integer

August 30th, 2012

The Convert to Integer code provider allows you to wrap an expression returning a non-integer value to Math.Ceiling, Math.Floor, or Math.Round. Consider the following code sample:

CodeRush Convert to Integer sample code

The method returns the sum of two input parameters as an integer. However, both input parameters are of the ‘double’ type. In this case, Visual Studio shows an error:

CodeRush Convert to Integer error window

To fix this error, we can apply the Convert to Integer code provider and choose the rounding method:

CodeRush Convert to Integer preview

Once the code provider is applied, the code is modified according to the preview hint:

CodeRush Convert to Integer result

—–
Products: CodeRush Pro
Versions: 12.1 and up
VS IDEs: 2008 and up
Updated: Aug/30/2012
ID: C181

Similar Posts: