1.9. C # operator

发布时间 : 2025-10-25 13:34:36 UTC      

Page Views: 9 views

An operator is a symbol that tells the compiler to perform a specific mathematical or logical operation. C # has a wealth of built-in operators, classified as follows:

  • Arithmetic operator

  • Relational operator

  • Logical operator

  • Bit operator

  • Assignment operator

  • Other operators

This tutorial will cover arithmetic operators, relational operators, logicaloperators, bit operators, assignment operators, and other operators one by one.

1.9.1. Arithmetic operator #

The following table shows all the arithmetic operators supported by C #. Hypothetical variable A , value is 10, variable B is 20, then:

Operator

Description

Example

+

Add up the two operands

A + B will get 30

-

Subtract the second Operand from the first Operand

A-B will get-10

*

Multiply two operands

A * B will get 200

/

Numerator divided by denominator

B / A will get 2.

%

Take the modular operator, the remainder after division

B% A will get 0

++

Self-increment operator, the integer value increases by 1

Atom + will get 11.

--

Self-subtraction operator, integer value minus 1

Amure-will get 9

Example #

Take a look at the following example for all the arithmetic operators available in C#:

Example

using System; namespace OperatorsAppl { class Program { static void Main(string[] args) { int a = 21; int b = 10; int c; c = a + b; Console.WriteLine("The 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("The value of Line 4- c is {0}", c); c = a % b; Console.WriteLine("The value of Line 5- c is {0}", c); // ++a Perform autoincrement operation before assigning values c = ++a; Console.WriteLine("The value of Line 6- c is {0}", c); // At this point, the value of a 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 31 The value of Line 2- c is 11 The value of Line 3- c is 210 The value of Line 4- c is 2 The value of Line 5- c is 1 The value of Line 6- c is 22 The value of Line 7-c is 21 
  • c = a++ : First assign a to c, and then perform a self-increment operation on a

  • c = ++a : First perform the self-increment operation of a, and then assign a to c

  • c = a-- : First assign a to c, and then self-subtract a.

  • c = --a : Self-subtract a first, and then assign a to c

Example

using System; namespace OperatorsAppl { class Program { static void Main(string[] args) { int a = 1; int b; // a++ Assign values first and then perform autoincrement operation b = a++; Console.WriteLine("a = {0}", a); Console.WriteLine("b = {0}", b); Console.ReadLine(); // ++a Perform autoincrement operation before assigning values a = 1; // Reinitialize a b = ++a; Console.WriteLine("a = {0}", a); Console.WriteLine("b = {0}", b); Console.ReadLine(); // a-- Assign values first and then perform self subtraction operations a = 1; // Reinitialize a b= a--; Console.WriteLine("a = {0}", a); Console.WriteLine("b = {0}", b); Console.ReadLine(); // --a Perform self subtraction before assigning values a = 1; // Reinitialize a b= --a; Console.WriteLine("a = {0}", a); Console.WriteLine("b = {0}", b); Console.ReadLine(); } } } 
《地理信息系统原理、技术与方法》  97

最近几年来,地理信息系统无论是在理论上还是应用上都处在一个飞速发展的阶段。 GIS被应用于多个领域的建模和决策支持,如城市管理、区划、环境整治等等,地理信息成为信息时代重要的组成部分之一; “数字地球”概念的提出,更进一步推动了作为其技术支撑的GIS的发展。 与此同时,一些学者致力于相关的理论研究,如空间感知、空间数据误差、空间关系的形式化等等。 这恰好说明了地理信息系统作为应用技术和学科的两个方面,并且这两个方面构成了相互促进的发展过程。