Found 2628 Articles for Csharp

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

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

73 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

What is the use of ‘new’ keyword in C#?

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

700 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

Fibonacci Series in C#

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

6K+ 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

How to calculate the 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

What is the use of sizeof Operator in C#?

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

347 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

What types of loops are supported in C#?

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

96 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

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

karthikeya Boyini
Updated on 20-Jun-2020 13:20:50

124 Views

The Array.LongLength property gets a 64-bit integer that represents the total number of elements in all the dimensions of the Array.Let’s say your array of long data type is −long[,] arr1= new long[15, 35];Use the LongLength property to get an integer representing the total number of elements in all dimensions of the Array −arr1.LongLengthLet us see an example to implement the Array.LongLength property of array class −Example Live Demousing System; class Program {    static void Main() {       long[,] arr1= new long[15, 35];       long len1 = arr1.GetLongLength(0);       Console.WriteLine(len1);       Console.WriteLine(arr1.LongLength);    } }Output15 525

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

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

56 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 implement Array.Length property of array class −Example Live Demousing System; using System.Collections.Generic; using System.Linq; using System.Text; namespace lower {    class Program {       static void Main(string[] args) {          Array arr = Array.CreateInstance(typeof(String), 3);          arr.SetValue("Electronics", 0);         ... Read More

What is overloading in C#?

Samual Sam
Updated on 20-Jun-2020 13:22:01

2K+ Views

C# provides two techniques to implement static polymorphism −Function overloadingOperator overloadingFunction OverloadingTwo or more than two methods having the same name but different parameters is what we call function overloading in C#.Function overloading in C# can be performed by changing the number of arguments and the data type of the arguments.Let’s say you have a function that prints multiplication of numbers, then our overloaded methods will have the same name but different number of arguments −public static int mulDisplay(int one, int two) { } public static int mulDisplay(int one, int two, int three) { } public static int mulDisplay(int one, ... Read More

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

karthikeya Boyini
Updated on 20-Jun-2020 13:23:19

80 Views

The Array.IsReadOnly property gets a value indicating whether the Array is read-only.Firstly, set the array values −Array arr = Array.CreateInstance(typeof(String), 3); arr.SetValue("Electronics", 0); arr.SetValue("Clothing", 1);Now let’s use the IsReadOnly property to find whether the Array is read-only. If the array is read-only, then it cannot be updated −arr.IsReadOnlyThe following is the complete example stating the usage of Array.IsReadOnly property −Example Live Demousing System; using System.Collections.Generic; using System.Linq; using System.Text; namespace lower {    class Program {       static void Main(string[] args) {          Array arr = Array.CreateInstance(typeof(String), 3);          arr.SetValue("Electronics", 0);   ... Read More

Advertisements