How to use the arithmetic operator of C #
This article mainly introduces "how to use the arithmetic operator of C#". In the daily operation, I believe that many people have doubts about how to use the arithmetic operator of C#. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubt about how to use the arithmetic operator of C#! Next, please follow the editor to study!
Example
Take a look at the following example for all the arithmetic operators available in C#:
Using System
Namespace OperatorsAppl
{
Class Program
{
Static void Main (string [] args)
{
Int a = 21
Int b = 10
Int c
C = a + b
Console.WriteLine (value of "Line 1-c is {0}", c)
C = a-b
Console.WriteLine (the value of "Line 2-c is {0}", c)
C = a * b
Console.WriteLine (the value of "Line 3-c is {0}", c)
C = a / b
Console.WriteLine (value of "Line 4-c is {0}", c)
C = a% b
Console.WriteLine (the value of "Line 5-c is {0}", c)
/ / + + a perform self-increment operation first and then assign values
C = + + a
Console.WriteLine (value of "Line 6-c is {0}", c)
/ / the value of an at this time is 22
/ /-- a perform self-subtraction before assigning values
C =-- a
Console.WriteLine (the value of "Line 7-c is {0}", c)
Console.ReadLine ()
}
}
}
When the above code is compiled and executed, it produces the following results:
The value of Line 1-c is 31Line 2-c, the value of 11Line 3-c is the value of 210Line 4-c, the value of 2Line 5-c is the value of 1Line 6-c, the value of 22Line 7-c is 21.
C = an increment: first assign a to c, and then perform a self-increment operation on a.
C = + + a: first perform a self-increment operation, and then assign a to c.
C = a Murray: first assign a to c, then perform a self-subtraction operation on a.
C =-- a: first self-subtract a, and then assign a to c.
At this point, the study of "how to use the arithmetic operator of C #" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!