1.14. C # switch statement

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

One switch statement allows you to test when a variable is equal to multiple values. Each value is called a case and the variable being tested will be for each switch case to check it out.

1.14.1. C # nested switch statement #

You can put one switch as an external switch , part of the statement sequence that can be found in a switch , use another within thestatement switch . Even internally and externally switch of case constants contain common values and there is no contradiction.

Grammar #

Nesting in C # switch syntax of the statement:

switch(ch1)
{
   case 'A':
      printf("This A is part of the external switch" );
      switch(ch2)
      {
         case 'A':
            printf("This A is part of the internal switch" );
            break;
         case 'B': /* Internal B case code */
      }
      break;
   case 'B': /* External B case code */
}

Example #

using System;
namespace DecisionMaking
{

    class Program
    {
        static void Main(string[] args)
        {
            int a = 100;
            int b = 200;
            switch (a)
            {
                case 100:
                    Console.WriteLine("This is part of the external switch");
                    switch (b)
                    {
                        case 200:
                        Console.WriteLine("This is part of the internal switch");
                        break;
                    }
                    break;
            }
            Console.WriteLine("The exact value of a is {0}", a);
            Console.WriteLine("The exact value of b is {0}", b);
            Console.ReadLine();
        }
    }
}

When the above code is compiled and executed, it produces the following results:

This is part of the external switch
This is part of the internal switch
The accurate value of a is 100
The accurate value of b is 200

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.