Samual Sam has Published 2310 Articles

How to instantiate a class in C#?

Samual Sam

Samual Sam

Updated on 22-Jun-2020 12:13:46

4K+ Views

Use the new operator to instantiate a class in C#.Let’s say our class is Line. Instantiation will create a new object as shown below −Line line = new Line();Using the object, you can now call the method −line.setLength(6.0);Let us see the example −Example Live Demousing System; namespace LineApplication {   ... Read More

How to iterate efficiently through an array of integers of unknown size in C#

Samual Sam

Samual Sam

Updated on 22-Jun-2020 12:12:32

505 Views

To iterate efficiently through an array of integers of unknown size in C# is easy. Let’s see how.Firstly, set an array, but do not set the size −int[] arr = new int[] { 5, 7, 2, 4, 1 };Now, get the length and iterate through an array using for loop ... Read More

How to join or concatenate two lists in C#?

Samual Sam

Samual Sam

Updated on 22-Jun-2020 12:11:06

2K+ Views

To concatenate two lists, use AddRange() method.Set the first list −var products1 = new List < string > (); products1.Add("Belts"); products1.Add("Tshirt"); products1.Add("Trousers");Set the second list −var products2 = new List < string > (); products2.Add("Footwear"); products2.Add("Electronics");To concatenate both the lists −products1.AddRange(products2);The following is the complete code −Example Live Demousing System.Collections.Generic; using ... Read More

How to loop through all values of an enum in C#?

Samual Sam

Samual Sam

Updated on 22-Jun-2020 12:08:45

2K+ Views

To loop through all the values of enum, use the Enum.GetValues().Firstly, set an Enum −public enum Grade { A, B, C, D, E, F };Now, with foreach loop, you need to loop through Enum.GetValues(typeof(Grade)) −foreach (Grade g in Enum.GetValues(typeof(Grade))) {    Console.WriteLine(g); }Here is the complete code −Example Live Demousing System; ... Read More

How to initialize a dictionary to an empty dictionary in C#?

Samual Sam

Samual Sam

Updated on 22-Jun-2020 11:59:00

14K+ Views

To initialize a dictionary to an empty dictionary, use the Clear() method. It clears the dictionary and forms it as empty.dict.Clear();After that, use the Dictionary count property to check whether the list is empty or not −if (dict.Count == 0) {    Console.WriteLine("Dictionary is empty!"); }Let us see the complete ... Read More

How does ‘FOR EACH ROW’ work in the MySQL trigger?

Samual Sam

Samual Sam

Updated on 22-Jun-2020 11:54:52

5K+ Views

Actually ‘FOR EACH ROW’ means for each of the matched rows that get either updated or deleted. In other words, we can say that trigger is not applied to each row, it just says to execute the trigger body for each affected table row. We can illustrate this by the ... Read More

How to input multiple values from user in one line in C#?

Samual Sam

Samual Sam

Updated on 22-Jun-2020 11:40:25

3K+ Views

Use a while loop to input multiple values from the user in one line.Let’s say you need to get the elements of a matrix. Get it using Console.ReadLine() as shown below −Console.Write("Enter elements - Matrix 1 : "); for (i = 0; i < m; i++) {    for (j ... Read More

How can we convert subqueries to INNER JOIN?

Samual Sam

Samual Sam

Updated on 22-Jun-2020 10:59:14

1K+ Views

To make it understand we are using the data from the following tables −mysql> Select * from customers; +-------------+----------+ | Customer_Id | Name     | +-------------+----------+ |           1 | Rahul    | |           2 | Yashpal  | |   ... Read More

How to convert Decimal to Binary using C#?

Samual Sam

Samual Sam

Updated on 22-Jun-2020 10:57:36

388 Views

Let’s say we want to convert the number 48 to binary.Firstly, set it and use the / and % operators and loop until the value is greater than 1 −decVal = 48; while (decVal >= 1) {    val = decVal / 2;    a += (decVal % 2).ToString(); ... Read More

LinkedList in C#

Samual Sam

Samual Sam

Updated on 22-Jun-2020 10:55:35

2K+ Views

System.Collections.Generic namespace is available in C# for LinkedList. The LinkedList class allows insertion and deletion of elements from the list at a fast pace.C# LinkedList class uses the concept of linked list. It allows us to insert and delete elements fastly. It can have duplicate elements. It is found in ... Read More

Advertisements