
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
Decision Making in C#
Decision making structures requires the programmer to specify one or more conditions to be evaluated or tested by the program, along with a statement or statements to be executed if the condition is determined to be true, and optionally, other statements to be executed if the condition is determined to be false.
Decision Making in C# includes if statement, if-else statement, switch statement, etc.
Let us see an example of if statement in C#.
Example
using System; namespace Demo { class Program { static void Main(string[] args) { int x = 5; // if statement if (x < 20) { /* if condition is true then print the following */ Console.WriteLine("x is less than 20"); } Console.WriteLine("value of x is : {0}", x); Console.ReadLine(); } } }
Output
x is less than 20 value of x is : 5
Let us see an example of if-else statement in C#. In this, if the first condition is false, the condition in the else statement will be checked.
Example
using System; namespace Demo { class Program { static void Main(string[] args) { int x = 100; /* check the boolean condition */ if (x < 20) { /* if condition is true then print the following */ Console.WriteLine("x is less than 20"); } else { /* if condition is false then print the following */ Cohttp://tpcg.io/HoaKexnsole.WriteLine("x is not less than 20"); } Console.WriteLine("value of a is : {0}", x); Console.ReadLine(); } } }
Output
x is not less than 20 value of a is : 100
- Related Articles
- Decision Making in C++
- What are decision making statements in C#?
- Decision Making in Java
- Group Decision Making
- Decision-Making in the Courtroom
- Theories of Decision Making
- Factors Influencing Decision Making
- Emotion Laden Consumer Decision Making
- Framework for Efficient Decision Making
- Adaptive Strategy Selection in Consumer Decision Making
- What Is Data-Driven Decision-Making?
- The decision-making concepts in C language using flow chart and programs
- What is meant by Consumer Decision-Making?
- Best Practices for Decision-making in the Business World
- Group Decision-Making and Leadership for Social Change

Advertisements