TAILIEUCHUNG - Using Arithmetic Operators

Sử dụng số học sử dụng C # hỗ trợ các phép tính số học thường xuyên bạn học được trong thời thơ ấu của bạn: các dấu cộng (+) cho Ngoài ra, dấu trừ (-) cho phép trừ, dấu sao (*) cho phép nhân, và các dấu gạch chéo (/) để phân chia . | Using Arithmetic Operators C supports the regular arithmetic operations you learned in your childhood the plus sign for addition the minus sign - for subtraction the asterisk for multiplication and the forward slash for division. These symbols - and are called operators as they operate on values to create new values. In the following example the variable moneyPaidToConsultant ends up holding the product of 750 the daily rate and 20 the number of days the consultant was employed long moneyPaidToConsultant moneyPaidToConsultant 750 20 NOTE The values that an operator operates on are called operands. In the expression 750 20 the is the operator and 750 and 20 are the operands. Determining an Operator s Values Not all operators are applicable to all data types so whether you can use an operator on a value depends on the value s type. For example you can use all the arithmetic operators on values of type char int long float double or decimal. However with one exception you can t use the arithmetic operators on values of type string or bool. So the following statement is not allowed because the string type does not support the minus operator subtracting one string from another would be meaningless compile time error Gillingham - Manchester City The exception is that the operator can be used to concatenate string values. The following statement writes 431 not 44 to the console 43 1 TIP You can use the method to convert a string value to an integer if you need to perform arithmetic computations on values held as strings. You should also be aware that the type of the result of an arithmetic operation depends on the type of the operands used. For example the value of the expression is the type of both operands is double in C literal numbers with decimal points are always double not float in order to maintain as much accuracy as possible and so the type of the result is also double. However the value of the .

Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.