Skip to main content

Posts

String in C# Explained

String in C# String  is a  keyword  that is use to represent a sequential collection of characters that is called a text and the string is an object of  System.String  type.   We use  string   keyword  to create string  variables  to hold the particular text which is a sequential collection of characters.   The string  variables  can hold any kind of text and by using  Length  property we can know the number of characters the string  variable  is holding.   Declaration and Initialization of string variable in C#   The following are the different ways of declaring and initializing string variables using  string   keyword.        // Declare without initializing.             string str1;             // Declaring and Initial...

Comments in C# Explained

Comments in C# Comments  are the self-explanatory notes to provide detailed information about our codes.   It’s always a good practice to include comments in our code so as to provide detailed information about what specific block or line of code can do. The comments benefit us or anyone else who examines the code at latter time.   We can include comments anywhere in the program without effecting our code and the comments do not affect the performance of an application because the comments won’t be compiled and executed by the compiler.   There are three types of comments available in C#, these are Single-line Comments Multi-line Comments XML Comments Single Line Comments in C# Single Line Comments  are defined by using // ( double forward slash ).   The single line comment syntax in C# is defined below.   // here is a single line comment in C# language. Single line comment starts with double forward slash and any statem...

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...