I'm going through the "Head First C#" book and in one of the chapters I created a program and uses variables declared as ints and decimals. Visual Studio got cranky with me a couple of times about mixing and matching the two. For example:
dinnerParty.NumberOfPeople = (int) numericUpDown1.Value;
NumberOfPeople is declared as an int and apparently numeric updowns are decimals.
Also, the book puts an M after some numbers when adding them together. For example:
public void SetHealthyOption(bool healthy)
{
if (healthy)
{
CostOfBeveragesPerPerson = 5.00M;
}
else
{
CostOfBeveragesPerPerson = 20.00M;
}
}
CostOfBeveragesPerPerson is declared as a decimal.
So I have two specific questions:
1) How can you know when you need to cast something? I'm sure there is quite a bit to casting... can anyone provide some good links to learn about casting?
2) What does the M after the numbers do?
EDIT
So the M denotes that the number is a decimal and not a double. Why not just cast the number as a decimal like: (decimal) 50.00? And what is that "function" called? If I wanted to see what "letters" were available what would I google?