Book Store  
  Contact Us  
  Links  
  Site Map  
C# Tutorials - More complex decisions

More complex decisions in C#

 

The examples so far have used simple decisions between one item and another. More complex decisions allow you to do things such as checking if A or B has been chosen. Program 3 using a more complex expression using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            string theAnswer;
            Console.WriteLine("Do you use C# ?");
            theAnswer = Console.ReadLine();
            if (theAnswer == "y" || answer = “Y”)
            {
                Console.WriteLine("Good");
            }
            else
            {
                Console.WriteLine("o dear");
            }
        }
    }
}

The above example uses the OR statement which evaluates to true if y or Y were typed by the user.