Types of Loops Supported in C#

George John
Updated on 20-Jun-2020 14:22:16

158 Views

A loop statement allows us to execute a statement or a group of statements multiple times. The following are the loops supported in C# −Sr.NoLoop Type & Description1while loopIt repeats a statement or a group of statements while a given condition is true. It tests the condition before executing the loop body.2for loopIt executes a sequence of statements multiple times and abbreviates the code that manages the loop variable.3do...while loopIt is similar to a while statement, except that it tests the condition at the end of the loop bodyWith C#, you can also use foreach loop as shown below −Example Live ... Read More

Rotate Div with Matrix Transforms Using CSS

Srinivas Gorla
Updated on 20-Jun-2020 14:22:10

288 Views

You can try to run the following code to rotate div with matrix transforms using CSS:ExampleLive Demo                    div {             width: 300px;             height: 100px;             background-color: pink;             border: 1px solid black;          }          div#myDiv1 {             /* IE 9 */             -ms-transform: matrix(1, -0.3, 0, 1, 0, 0);             /* Safari */             -webkit-transform: matrix(1, -0.3, 0, 1, 0, 0);             /* Standard syntax */             transform: matrix(1, -0.3, 0, 1, 0, 0);          }                              Welcome to my website.                      Welcome to my website.           Output

Use of sizeof Operator in C#

karthikeya Boyini
Updated on 20-Jun-2020 14:20:00

443 Views

The sizeof() datatype returns the size of a data type. Let’s say you need to find the size of int datatype −sizeof(int);For double datatype −sizeof(double);Let us see the complete example to find the size of various datatypes −Example Live Demousing System; namespace Demo {    class Program {       static void Main(string[] args) {          Console.WriteLine("The size of long is {0}", sizeof(long));          Console.WriteLine("The size of double is {0}", sizeof(double));          Console.ReadLine();       }    } }OutputThe size of long is 8 The size of double is 8

Calculate Power Exponent Value Using C#

Samual Sam
Updated on 20-Jun-2020 14:18:25

1K+ Views

To calculate the power exponent value, use the Math.pow() method.Here, n is the number and p is the power −double res = Math.Pow(n, p);The following is the complete code −Example Live Demousing System; class Program {    static void Main() {       double n, p;       n = 7;       p = 3;       Console.WriteLine("Exponent Power= "+n);       double res = Math.Pow(n, p);       Console.WriteLine("Result= {0}", res);       Console.ReadLine();    } }OutputExponent Power= 7 Result= 343

Fibonacci Series in C#

Arjun Thakur
Updated on 20-Jun-2020 14:17:48

7K+ Views

To find Fibonaccli series, firsty set the first two number in the series as 0 and 1.int val1 = 0, val2 = 1, vNow loop through 2 to n and find the fibonai series. Every number in the series is the sum of the last 2 elements −for(i=2;i

Use of New Keyword in C#

karthikeya Boyini
Updated on 20-Jun-2020 14:16:55

877 Views

Use the new keyword to create an instance of the array −int [] a = new int[5];The new operator is used to create an object or instantiate an object. Here in the example, an object is created for the class using the new −Example Live Demousing System; namespace CalculatorApplication {    class NumberManipulator {       public void swap(int x, int y) {          int temp;          temp = x; /* save the value of x */          x = y; /* put y into x */     ... Read More

Values Property of Hashtable Class in C#

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

137 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 {       static void Main(string[] args) {          Hashtable ht = new Hashtable();          ht.Add("One", "Henry");          ht.Add("Two", "Kevin");          ht.Add("Three", "David");          // Displaying values          foreach (string value in ht.Values) {             Console.WriteLine(value);          }          Console.ReadKey();       }    } }OutputDavid Henry Kevin

Values Property of SortedList Class in C#

Samual Sam
Updated on 20-Jun-2020 14:15:10

96 Views

Firstly, declare the SortedList class −SortedList list = new SortedList();Now add the values −list.Add("S1", "Wallets"); list.Add("S2", "Sunglasses"); list.Add("S3", "Backpacks");The following is the code to work with Values property of SortedList class −Example Live Demousing System; using System.Collections; namespace Demo {    class Program {       static void Main(string[] args) {          SortedList list = new SortedList();          list.Add("S1", "Wallets");          list.Add("S2", "Sunglasses");          list.Add("S3", "Backpacks");          foreach (string value in list.Values) {             Console.WriteLine(value);          }       }    } }OutputWallets Sunglasses Backpacks

Calculate Power of Three Using C#

George John
Updated on 20-Jun-2020 14:13:57

344 Views

For power of 3, se the power as 3 and apply a recursive code like the following snippet −if (p!=0) { return (n * power(n, p - 1)); }Let’s say the number is 5, then the iterations would be −power(5, 3 - 1)); // 25 power (5,2-1): // 5The above would return5*25 i.e 125 as shown below −Example Live Demousing System; using System.IO; public class Demo {    public static void Main(string[] args) {       int n = 5;       int p = 3;       long res;       res = power(n, p);       Console.WriteLine(res);    }    static long power (int n, int p) {       if (p!=0) {          return (n * power(n, p - 1));       }       return 1;    } }Output125

MySQL Evaluation of Non-Numeric Text Before Numbers in Quotes

Anjana
Updated on 20-Jun-2020 13:58:45

86 Views

Suppose if we are trying to add the numbers having non-numeric text before them, then MySQL simply evaluate the value of such number as 0. Following example will exhibit this −Examplemysql> Select 'Kg 1525' + 'Oz 200'As Total; +-------+ | Total | +-------+ | 0     | +-------+ 1 row in set, 2 warnings (0.00 sec) mysql> Select 'Kg 1525' + '200'As Total; +-------+ | Total | +-------+ | 200   | +-------+ 1 row in set, 1 warning (0.00 sec)

Advertisements