1.9. C # operator

发布时间 :2023-10-12 23:00:06 UTC      

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();
        }
    }
}

Principles, Technologies, and Methods of Geographic Information Systems  102

In recent years, Geographic Information Systems (GIS) have undergone rapid development in both theoretical and practical dimensions. GIS has been widely applied for modeling and decision-making support across various fields such as urban management, regional planning, and environmental remediation, establishing geographic information as a vital component of the information era. The introduction of the “Digital Earth” concept has further accelerated the advancement of GIS, which serves as its technical foundation. Concurrently, scholars have been dedicated to theoretical research in areas like spatial cognition, spatial data uncertainty, and the formalization of spatial relationships. This reflects the dual nature of GIS as both an applied technology and an academic discipline, with the two aspects forming a mutually reinforcing cycle of progress.