Converting methods to functions or procedures
The simplest type of method is one that performs a task without requiring any parameters and without returning any information – let’s call them procedures (or void methods). Methods that use some type as the return value – are functions.
Sometimes, when we declare a method with a return value, we may realize that we don’t actually need this return value, and instead, need a simple void method that does not return anything. On the other hand, we marked a method as void, but may require it to be a function, returning a value.
- Convert to Function
- Convert to Procedure
The Convert to Function code provider changes a method that returns void (or a Sub in VB) into a function that returns an appropriate type. The type is inferred from the returning value. This code provider will help you easily add a return type for a method and guess its correct type, for example:
The Convert to Procedure code provider converts a private function that returns some value into a method that returns void (or a Sub in VB). It will also change all “return something” statements into simple returns, for example:
—– Products: CodeRush Pro Versions: 11.1 and up VS IDEs: any Updated: Oct/31/2011 ID: C141