Skip to main content

Posts

Showing posts from April, 2020

Ternary Operator in C# Explained

Ternary Operator in C# C# includes a special type of decision making operator '?:' called the ternary operator. Ternary operator is a Conditional operator in C#. It takes three arguments and evaluates a Boolean expression. In another way, is a decision-making operator and it is a substitute of if…else statement    By using Ternary Operator, we can replace multiple lines of if…else statement code into a single line in C#.   The Ternary operator will help you to execute the statements based on the defined conditions using the decision-making operator ( ?: ).   Syntax of Ternary Operator in C#   The Ternary Operator will always work with  3  operands. Following is the syntax of defining a Ternary Operator in C#.   condition_expression ? first_expression : second_expression;   From the above example, we can see the Ternary Operator syntax, the conditional operator (?:) will return only one value fr...

Keywords in C#

Keywords in C# Explained Keywords  in C# are the predefined set of reserved words that have special meaning for the compiler. So the keywords cannot be used as identifiers such as variable name, class name, etc. in applications.   Keywords as Variable Names   In case you want to use Keywords as variable names (identifiers), then you need to include  @  as a prefix for your variable names. For example,  @switch  is a valid identifier but the  switch  is not because it’s a keyword and having a special meaning for the compiler.   The following code example shows how to use the reserved keywords as variable names by including  @  as a prefix.   using System; namespace CsharpnaijaTutorial {     public class @switch     {         public int @case;     }     class Program     {  ...