Error: is a 'field' but is used like a 'type' c#

I have a global variable averagel that I am trying to manipulate in a method. The compiler doesn't have a problem with me setting the value averagel = averagel / (xrestriction * yrestriction); but for some reason it doesn't like it when I try to use it to set another variable:

inside = (inside + averagel * (xrestriction * yrestriction)) - 2 * (averagel)(suml);

Only on the line where I try to use averagel's value to set another int does it return the error 'sqlDataReader.ReaderDemo.averagel' is a 'field' but is used like a 'type'. I also tried setting an int in the method to the value of averagel and then trying to use that value to set my inside variable but that returned with an error of "The type or namespace name 'test' could not be found (are you missing a using directive or an assembly reference?)" and all I did the line before was declare int test=averagel;

Any ideas what could be going on here?


You probably need an asterisk:

inside = (inside + averagel * (xrestriction * yrestriction)) - 2 * averagel * suml; 

You can't multiply two values in C# like you can in mathematics. E.g. (averagel)(suml) makes sense in a math equation but you have to write averagel * suml in C#.

You've got your parentheses wrong and accidentally included a typecast in the expression. The bit at the end

(averagel) (suml)

Tries to cast suml to type averagel, and so the compiler's right to complain. I suspect you're missing an operator between those two terms.

Need Your Help

Scrolling RecycleView that is inside AppBarLayout disables scrollFlag when scrolling outer RecycleView

android android-recyclerview android-coordinatorlayout android-appbarlayout

While i haven't touched the inner RecycleView, scrolling the outer RecycleView moves the content as desired, but after i have scrolled the inner RecycleView and then tried to scroll the outer Recyc...

String replacement in a text file

linux sed awk grep

i have a text file "out" like below,