For comparisons / evaluations of objects of the same class(and other purposes), is it better to define a static or a non-static (is this called "dynamic" by chance?) function?
Sample code:
class student
{
internal decimal medianOfMarks()
{
int count = 0;
decimal sum = 0;
foreach(float mark in reportCard)
{
counter++;
sum += mark;
}
return sum / count;
}
**OR**
internal static decimal medianOfMark(student delinquent)
{
[same logic]
}
}
Let's not consider making the function a property, though parameterless, since I'd like an answer applicable to parameterized functions as well.
What are arguments pro / con each approach?
What deciding factors do exist?
I've already thought into this myself, but I don't want to bias the discussion with my opinion.
I am by far not concerned about running out of memory. – Mark Jun 16 '14 at 11:30
ReportCard
. If you need this on the student, you should forward the call toReportCard
. 2) You should use a generic averaging method which takes a sequence of numbers and outputs a number. Such asEnumerable.LINQ
3) I wouldn't usefloat
on the report card. Either go withdecimal
or with integers representing fixed point numbers.