Ankith Reddy has Published 996 Articles

What is a Ternary operator/conditional operator in C#?

Ankith Reddy

Ankith Reddy

Updated on 20-Jun-2020 15:55:02

406 Views

Ternary operator is a Conditional operator in C#. It takes three arguments and evaluates a Boolean expression.For example −y = (x == 1) ? 70 : 100;Above, if the first operand evaluates to true (1), the second operand is evaluated. If the first operand evaluates to false (0), the third ... Read More

How to calculate fractional power using C#?

Ankith Reddy

Ankith Reddy

Updated on 20-Jun-2020 15:24:02

591 Views

To calculate fractional power in C#, use the Math.Pow method.The following sets 5 to the power 3.7 −double res = Math.Pow(5, 3.7);The following is the complete example showing how to calculate fractional power in C# −Example Live Demousing System; class Program {    static void Main() {       double ... Read More

How to demonstrate Prefix Operator using C#?

Ankith Reddy

Ankith Reddy

Updated on 20-Jun-2020 15:16:55

260 Views

The increment operator is ++ operator. If used as prefix on a variable, the value of variable gets incremented by 1. After that the value is returned unlike Postfix operator. It is called Prefix increment operator. In the same way the decrement operator works but it decrements by 1.For example, ++a;The ... Read More

How to use #if..#elif…#else…#endif directives in C#?

Ankith Reddy

Ankith Reddy

Updated on 20-Jun-2020 15:07:13

1K+ Views

All preprocessor directives begin with #, and only white-space characters may appear before a preprocessor directive on a line. Preprocessor directives are not statements, so they do not end with a semicolon (;).#ifThe #if directive allows testing a symbol or symbols to see if they evaluate to true.#elseIt allows to ... Read More

Stack and Queue in C#

Ankith Reddy

Ankith Reddy

Updated on 20-Jun-2020 15:02:54

6K+ Views

StackStack class represents a last-in, first out collection of object. It is used when you need a last-in, first-out access of items.The following is the property of Stack class −Count− Gets the number of elements in the stack.The following are the methods of Stack class −Sr.No.Method & Description1public virtual void ... Read More

How to assign same value to multiple variables in single statement in C#?

Ankith Reddy

Ankith Reddy

Updated on 20-Jun-2020 14:35:30

3K+ Views

To assign same value to multiple variables in a single line, use the = operator −val1 = val2 = 20;The above statement assigns 20 to the variables val1 and val2 as shown in the following code −Example Live Demousing System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Demo {   ... Read More

What is the Values property of Hashtable class in C#?

Ankith Reddy

Ankith Reddy

Updated on 20-Jun-2020 14:15:50

126 Views

The Values property gets an ICollection containing the values in the Hashtable.Declare Hashtable collection −Hashtable ht = new Hashtable();Now add valuesht.Add("One", "Henry"); ht.Add("Two", "Kevin"); ht.Add("Three", "David");To display values from Hashtable, the following is the code −Example Live Demousing System; using System.Collections; namespace Demo {    class Program {     ... Read More

How does MySQL IF() function work?

Ankith Reddy

Ankith Reddy

Updated on 20-Jun-2020 13:22:56

157 Views

MySQL IF() function is one of the MySQL control flow functions that returns a value based on a condition. It is sometimes referred to as IF ELSE or IF THEN ELSE function. Basically, it takes three expressions and if the first expression is true (not ZERO and not NULL), it ... Read More

What does Array.Length property of array class do in C#?

Ankith Reddy

Ankith Reddy

Updated on 20-Jun-2020 13:21:19

108 Views

The Array.Lenth property in C# is used to find the length of the array.Let’s set the array class first −Array arr = Array.CreateInstance(typeof(String), 3); arr.SetValue("Electronics", 0); arr.SetValue("Clothing", 1); arr.SetValue("Appliances", 2);Now since the array’s length is 3, the Length property will give the result 3 −arr.LengthThe following is the code to ... Read More

What are the difference between Composition and Aggregation in C#?

Ankith Reddy

Ankith Reddy

Updated on 20-Jun-2020 13:19:02

563 Views

Under Composition, if the parent object is deleted, then the child object also loses its status. The composition is a special type of Aggregation and gives a part-of relationship.For example, A Car has an engine. If the car is destroyed, the engine is destroyed as well.public class Engine {    . ... Read More

Advertisements