Samual Sam has Published 2492 Articles

How do we use foreach statement to loop through the elements of an array in C#?

Samual Sam

Samual Sam

Updated on 23-Jun-2020 14:28:39

256 Views

A foreach loop is used to execute a statement or a group of statements for each element in an array or collection.It is similar to for Loop; however, the loop is executed for each element in an array or group. Therefoe, the index does not exist in it.Let us see ... Read More

How to sort a list of dictionaries by values of dictionaries in C#?

Samual Sam

Samual Sam

Updated on 23-Jun-2020 14:26:29

371 Views

Set the list of dictionaries with keys and values.var d = new Dictionary(); d.Add("Zack", 0); d.Add("Akon", 3); d.Add("Jack", 2); d.Add("Tom", 1);Get and sort the keys.var val = d.Keys.ToList(); val.Sort();You can try to run the following code to sort a list of dictionaries by values.Example Live Demousing System; using System.Collections.Generic; using System.Linq; ... Read More

How to split a string with a string delimiter in C#?

Samual Sam

Samual Sam

Updated on 23-Jun-2020 14:24:32

668 Views

Delimiters are the commas that you can see in the below string.string str = "Welcome, to, New York";Now set the delimiter separately.char[] newDelimiter = new char[] { ', ' };Use theSplit() method to split the string considering the delimiter as the parameter.str.Split(newDelimiter, StringSplitOptions.None);To split a string with a string deli ... Read More

How do we call a C# method recursively?

Samual Sam

Samual Sam

Updated on 23-Jun-2020 14:21:46

236 Views

To call a C# method recursively, you can try to run the following code. Here, Factorial of a number is what we are finding using a recursive function display().If the value is 1, it returns 1 since Factorial is 1.if (n == 1) return 1;If not, then the recursive function ... Read More

How to use the SetValue(,) method of array class in C#?

Samual Sam

Samual Sam

Updated on 23-Jun-2020 14:17:33

1K+ Views

The SetValue() method sets a value to the element at the specified position in the one-dimensional Array. The index is specified as a 32-bit integer.Firstly, set the array.Array arr = Array.CreateInstance(typeof(String), 6);No set values to the element using the SetValue() method.arr.SetValue("One", 0); arr.SetValue("Two", 1); arr.SetValue("Three", 3); arr.SetValue("Four", 4); arr.SetValue("Five", 5);The ... Read More

How to use Try/catch blocks in C#?

Samual Sam

Samual Sam

Updated on 23-Jun-2020 14:14:50

2K+ Views

Exceptions provide a way to transfer control from one part of a program to another. C# exception handling is built upon four keywords: try, catch, finally, and throw.try − A try block identifies a block of code for which particular exceptions is activated. It is followed by one or more ... Read More

How to set the maximum width of an element with JavaScript?

Samual Sam

Samual Sam

Updated on 23-Jun-2020 13:27:41

2K+ Views

Use the maxWidth property in JavaScript to set the maximum width.ExampleYou can try to run the following code to set the maximum width of an element with JavaScript −Live Demo           Click below to set Maximum width.       Max Width       ... Read More

How to set the space between characters in a text with JavaScript?

Samual Sam

Samual Sam

Updated on 23-Jun-2020 13:05:42

338 Views

To set the space between characters, use the JavaScript letterSpacing property.ExampleYou can try to run the following code to set the space between characters in a text with JavaScript −Live Demo           Heading 1       This is Demo Text.       Set Space between characters                function display() {             document.getElementById("myID").style.letterSpacing = "7px";          }          

How to use the GetLowerBound method of array class in C#

Samual Sam

Samual Sam

Updated on 23-Jun-2020 12:46:53

319 Views

The GetLowerBound() method of array class in C# gets the lower bound of the specified dimension in the Array.Firstly, set the array and get the lower bound as shown below −arr.GetLowerBound(0).ToString()The following is an example stating the usage of GetLowerBound() method in C#.Example Live Demousing System; using System.Collections.Generic; using System.Linq; using ... Read More

How to use the GetUpperBound method of array class in C#?

Samual Sam

Samual Sam

Updated on 23-Jun-2020 12:43:25

842 Views

The GetUpperBound() method of array class in C# gets the upper bound of the specified dimension in the Array.Firstly, set the array and get the upperbound as shown below −arr.GetUpperBound(0).ToString()The following is an example stating the usage of GetUpperBound() method in C#.Example Live Demousing System; using System.Collections.Generic; using System.Linq; using System.Text; ... Read More

Advertisements