namespace DatabasePricing.SumRounding
{
public class Roundedsum
{
public void checkinsum(int productid,int sum)
{
//Checks in price in the price table
//dbobject("price",productid,sum);
int temp_int = sum;
}
}
public class UnRoundedSum : Roundedsum
{
public void checkinsum(int productid,float sum)
{
//Since the sum is a float it will check the difference
//into unroundedsum table in the database
int intsum = (int)sum;
float tempfloat = sum - intsum;
//Check this remaining float into the database under unaccounted
// dbobject("unroundedsum",productid,tempfloat);
//Now call the integer checksum with the integer value
checkinsum(productid,intsum);
}
}
}
This is let us assume a main function i have created for testing rite now since it is not working in my project .Well this is like a testing object for the above classes.
using DatabasePricing.SumRounding;
namespace DatabasePricing
{
class testingrounding
{
static void Main() {
int product_id = 1;
float float_value = 1.1f;
UnRoundedSum obj1 = new UnRoundedSum();
//This call produces StackOverflow Exception
obj1.checkinsum(1, float_value);
int price = 200;
//I tried with integer value to test RoundedSum object
//it is still throwing an exception
//This call also produces StackOverflow Exception
obj1.checkinsum(1, price);
}
}
}
When i try to debug it is always caught in checkinsum() before it throws the StackOverflow error.. When i tried debugging it comes back into checkinsum() even after executing it. it keeps coming back for some reason. i dont know what could go so wrong.
The C# standard states that "methods in a base class are not candidates if any method in a derived class is applicable". In other words, checkinsum(int,float)
will always be preferred over base.checkinsum(int,int)
when calling checkinsum(1,1)
because the former is in the derived class and C# allows an int
to be implicitly cast to a float
.
See: https://learn.microsoft.com/en-us/archive/blogs/ericlippert/future-breaking-changes-part-three