how to combine multiple lines into one?

I am trying to figure out a way of combining the below Dim statements into one line and maybe also combining Return dblResult into there. currently it is three lines and I have been told that it is possible but kind of lost of how to do it - can anyone lend a hand please?

` Private Function CalcAreaFromRadius(ByVal radius As Double) As Double

    Dim dblRadiusSquared As Double = radius * radius
    Dim dblResult As Double = dblRadiusSquared * Math.PI

    Return dblResult

End Function`

Thanks

Answers


Given this is a relatively simple calculation, there's no reason why you can't simplify this down to one line like so:

Private Function CalcAreaFromRadius(ByVal radius As Double) As Double

    Return radius * radius * Math.PI

End Function

While it's not a good idea to put a large number of stuff on one line, you can always use : to put two lines of code in one line in VB:

Canonical example:

Class Test
     Inherits BaseClass

is equivalent to:

Class Test : Inherits BaseClass

Of course, as long as you are declaring variables on a single type without an explicit initialization expression, you can do that in one Dim statement:

Dim a, b as Integer

Return (radius * radius) * Math.PI

Need Your Help

std::thread with movable, non-copyable argument

c++ multithreading c++11 rvalue-reference

The following program doesn't build in VS11 beta, gcc 4.5, or clang 3.1

Sorting 'numbers' with multiple decimal points

javascript sorting decimal-point

I've got a bunch of "numbers" that have multiple decimal points (so they're really strings). However, I want to sort them as if they were numbers.