Decimals, ints, casting ... oh mine!

I am looking at the book “Head First C #,” and in one of the chapters I created a program and uses variables declared as ints and decimal numbers. Visual Studio shuddered several times with me about mixing and juxtaposing the two. For example:

dinnerParty.NumberOfPeople = (int) numericUpDown1.Value;

NumberOfPeople is declared as an int, and apparently the numeric updates are decimal.

In addition, the book places M after some numbers, adding them together. For example:

public void SetHealthyOption(bool healthy)
{
    if (healthy)
    {
        CostOfBeveragesPerPerson = 5.00M;
    }
    else
    {
        CostOfBeveragesPerPerson = 20.00M;
    }
}

CostOfBeveragesPerPerson is declared as decimal.

So, I have two specific questions:

1) How can you find out when you need to quit something? I'm sure there is a little for casting ... can anyone provide some good links to learn about casting?

2) What does M do after numbers?

EDIT

, M , , . : () 50,00? ? , "" , Google?

+3
3
  • , . , int , , , int. , int, , int , , .
  • M . , .
+6
Type    Suffix          Example
uint    U or u          100U
long    L or l          100L
ulong   UL or ul        100UL
float   F or f          123.45F
decimal M or m          123.45M

, #. - . , , , , . () 5.0 , 5.0m .

+3
  • Here's a good cast link directly from MSDN.
  • M tells the compiler that the number decimal, otherwise it will be considereddouble
+2
source

Source: https://habr.com/ru/post/1706258/


All Articles