Hot File

Here C# Nested Switch Statements

View: 211    Dowload: 0   Comment: 0   Post by: hanhga  
Author: none   Category: C / C++ / MFC   Fields: Other

9 point/1 review File has been tested

Like nested ifs, there is also a nested switch statement

Introduction

Like nested ifs, there is also a nested switch statement

In nested switches, a switch statement is declared inside other switch and so on

This is called inner or nested switch, this form is very useful for complex programs or real world examples such as user authentication where user enters his/her name and password for authentication, that user and password must be valid, if any one from these two will be invalid user can not be logged in and also can be view invalid messages

Example:

using System;
namespace csharpBasic
{
    // Start class definition / declaration.
    class Program
    {
        // Static main method void type declaration.
        static void Main(string[] args)
        {
    
            // 2 string variables are initialized.
            string userName = "admin", userPassword = "admin321";
 
            // An outer switch statement is declared.
            switch (userName)
            { // Outer switch is started.
 
                // This keyword (case) is associated with its outer switch statement.
                case "admin":
 
                    // Inner switch statement is declared.
                    switch (userPassword)
                    {
                       // This keyword (case) is associated with its inner switch statement.
                        case "admin321":
                            Console.WriteLine("You have successfully authenticated...");
                            break;
 
                        // This keyword (default) is associated with its inner switch statement.
                        default: 
                            Console.WriteLine("Invalid passwrod!");
                            break;
 
                    } // Inner switch statement is closed.
                    break;
 
                // This keyword (default) is associated with its outer switch statement.
                default: 
                    Console.WriteLine("Invalid user name!");
                    break;
            } // Outer switch statement is closed.
      
            Console.ReadKey();
 
        } // End of main method definition. 
    } // End of class. 
 
    /*
   The Output will be:
   You have successfully authenticated...
  */
}
?
 

Here C# Nested Switch Statements

Here C# Nested Switch Statements Posted on 07-09-2016  Like nested ifs, there is also a nested switch statement 9/10 211

Comment:

To comment you must be logged in members.

Files with category

  • How to Swap Two Numbers using Call by Reference in C

    View: 370    Download: 0   Comment: 0   Author: none  

    How to Swap Two Numbers using Call by Reference in C

    Category: C / C++ / MFC
    Fields: Other

    0/0 review
    How to swap two numbers using call by reference in C , C++. In the interviews interviewer generally asked the difference between call by reference and call by value

  • How to Print Fibonacci Series using Recursion in C, C++

    View: 376    Download: 0   Comment: 0   Author: none  

    How to Print Fibonacci Series using Recursion in C, C++

    Category: C / C++ / MFC
    Fields: Other

    4.5/1 review
    Write a program to print Fibonacci Series using recursion. Fibonacci series is a very important program in terms of interviews. To make this program little tough interviewer ask to write a fibonacci series code using recursion.

  • How to Implicitly Typed Arrays In C#

    View: 410    Download: 0   Comment: 0   Author: none  

    How to Implicitly Typed Arrays In C#

    Category: C / C++ / MFC
    Fields: Other

    0/1 review
    When we initialize these type of arrays with any data type, the compiler convert these arrays into that data type at compile time.

  • How to C# Static vs Instance Methods As Event Handlers

    View: 286    Download: 0   Comment: 0   Author: none  

    How to C# Static vs Instance Methods As Event Handlers

    Category: C / C++ / MFC
    Fields: Other

    0/0 review
    Both static and instance methods can be used as event handlers in C#

  • Build Pass By Reference To Method In C#

    View: 439    Download: 0   Comment: 0   Author: none  

    Build Pass By Reference To Method In C#

    Category: C / C++ / MFC
    Fields: Other

    0/3 review
    Like value types such as int, double, char etc. We can also pass a reference variable to the method in C# as its parameter which allows us to pass an object to the method and it is called pass by reference to method in C#.

  • How to C# Continue Statement

    View: 273    Download: 0   Comment: 0   Author: none  

    How to C# Continue Statement

    Category: C / C++ / MFC
    Fields: Other

    0/2 review
    continue statement skips or exits the current execution of a loop by given condition and keep execution continue for its next iteration unlike break statement it does not exit or terminate from loops, it terminates only its current execution

  • How to Single Dimensional Arrays In C#

    View: 212    Download: 0   Comment: 0   Author: none  

    How to Single Dimensional Arrays In C#

    Category: C / C++ / MFC
    Fields: Other

    0/1 review
    Single Dimensional Arrays in C# store each individual element at their single dimension, position or a specific location, that location is called an array index. Each index describes the position of each element within an array. Each element in an...

  • Build C# Multilevel Inheritance

    View: 236    Download: 0   Comment: 0   Author: none  

    Build C# Multilevel Inheritance

    Category: C / C++ / MFC
    Fields: Other

    2.5/2 review
    C# supports multilevel inheritance, suppose we have four classes A, B, C and D. Class A can inherit to B, B to C and C can inherit to D and so on now class D has all public members of class A, B and C include its own.

 
Newsletter Email

File suggestion for you

File top downloads

logo codetitle
Codetitle.com - library source code to share, download the file to the community
Copyright © 2015. All rights reserved. codetitle.com Develope by Vinagon .Ltd