Core C#

Switch Statements

This C# program demonstrates how to use the switch statement.

Program.cs

using System;

namespace XoaX {
    class Program {
        static void Main(string[] args) {
            int[] siNumbers = new int[] { 0, 1, 2, 999 };
            string sCreed = "";
            foreach (int i in siNumbers) {
                sCreed = "I believe in ";
                switch (i) {
                    case 0: {
                            sCreed += "God, the Father Almighty.";
                            break;
                        }
                    case 1: {
                            sCreed += "Jesus Christ, His only son.";
                            break;
                        }
                    case 2: {
                            sCreed += "the Holy Spirit.";
                            break;
                        }
                    default: {
                            sCreed += "one, holy, catholic, and apostolic Church.";
                            break;
                        }
                }
                Console.WriteLine(sCreed);
            }
        }
    }
}
 

Output

I believe in God, the Father Almighty.
I believe in Jesus Christ, His only son.
I believe in the Holy Spirit.
I believe in one, holy, catholic, and apostolic Church.
Press any key to continue . . .
 
 

© 2007–2024 XoaX.net LLC. All rights reserved.