Possible duplicate:
Why can't I remove the int as a decimal number?
Ok, C # /. NET guru, can someone tell me why this works:
static void Main(string[] args)
{
int _int = 0;
decimal _decimal = 1;
_int = (int)_decimal;
Console.ReadLine();
}
... but none of them do?
static void Main(string[] args)
{
int _int = 0;
decimal d = 1;
object _decimal = d;
_int = (int)_decimal;
Console.ReadLine();
}
static void Main(string[] args)
{
int _int = 0;
object _decimal = 1M;
_int = (int)_decimal;
Console.ReadLine();
}
I can use the decimal value for int while I am explicitly declared to be the decimal type from it, but I can not distinguish decimal from int when the decimal mark is stored in the type of the object? What's up with that?
NOTE. I know that I can probably use Convert.ToInt32 (), but I'm trying to figure out that this does not work here.
source
share