The Solutions 1 to 3 are good and resolve the above error.
But, it is worthwhile to review the design of the above
property
.
In the present case as seen from the code given in the question, there seems to be no requirement for having the
Type
of the
property coresubjectSecond
as
object
and the
Type
of the
back end store fcs_classwork
as
double
.
Since,
double
is a
ValueType
and
object
is
Reference Type
there will be an
overhead of boxing and unboxing
due to the above design, which may be costly particularly when the property is used excessively.
So, it is better to change the
Type of back end store
fcs_classwork to
object
or change the Type of the property coresubjectSecond to
double
as per the requirement, as a consequence the above
error can be avoided
as shown below
private double fcs_classwork;
public double coresubjectSecond
{
get { return fcs_classwork; }
set { fcs_classwork = value; }
}
Further, as seen from the code the
property
is being used like a
field
without any additional code in
getter and setter blocks
of the property. Hence, if
C# 3.0
and above is used, then the
auto implemented property
can be used in this case which will reduce the code clutter and improve the code readability as shown below
public double coresubjectSecond {get; set;}