Karthikeya Boyini has Published 2193 Articles

ToDictionary method in C#

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 14:28:32

2K+ Views

The ToDictionary method is an extension method in C# and converts a collection into Dictionary.Firstly, create a string array −string[] str = new string[] {"Car", "Bus", "Bicycle"};Now, use the Dictionary method to convert a collection to Dictionary −str.ToDictionary(item => item, item => true);Here is the complete code −Example Live Demousing System; ... Read More

C# program to Loop over a two dimensional array

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 14:13:58

5K+ Views

Declare a two dimensional array −string[, ] array = new string[3, 3];Set elements in the array −array[0, 0] = "One"; array[0, 1] = "Two"; array[0, 2] = "Three"; array[1, 0] = "Four"; array[1, 1] = "Five"; array[1, 2] = "Six"; array[2, 0] = "Seven"; array[2, 1] = "Eight"; array[2, 2] ... Read More

How can I generate days from the range of dates with the help of MySQL views?

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 14:11:56

330 Views

To illustrate it we are creating the following views −mysql> CREATE VIEW digits AS     -> SELECT 0 AS digit UNION ALL     -> SELECT 1 UNION ALL     -> SELECT 2 UNION ALL     -> SELECT 3 UNION ALL     -> SELECT 4 UNION ... Read More

C# program to find the index of an element in a List

karthikeya Boyini

karthikeya Boyini

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

1K+ Views

Set a list and add elements −List val = new List(); // integer elements val.Add(35); val.Add(55); val.Add(68);Let’s say now we need to find the index of element 68. For that, use the IndexOf() method −int index = val.IndexOf(68);Here is the complete code −Example Live Demousing System; using System.Collections.Generic; public class ... Read More

C# Program to find the smallest element from an array using Lambda Expressions

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 14:09:40

545 Views

Declare an array −int[] arr = { 10, 15, 5, 20};Now to get the smallest element from an array, use Min() method with lambda expressions −arr.Min());Here is the complete code −Example Live Demousing System; using System.Linq; class Demo {    static void Main() {       int[] arr = { ... Read More

C# program to get the List of keys from a Dictionary

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 14:08:38

6K+ Views

Set the dictionary elements −Dictionary d = new Dictionary(); // dictionary elements d.Add(1, "One"); d.Add(2, "Two"); d.Add(3, "Three"); d.Add(4, "Four"); d.Add(5, "Five"); d.Add(6, "Six"); d.Add(7, "Seven"); d.Add(8, "Eight");To get the keys, use a list collection −List keys = new List(d.Keys);Loop through the keys and display them.Here is the complete ... Read More

Insert more than one element at once in a C# List

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 14:07:28

3K+ Views

Use the InsertRange() method to insert a list in between the existing lists in C#. Through this, you can easily add more than one element to the existing list.Let us first set a list −List arr1 = new List(); arr1.Add(10); arr1.Add(20); arr1.Add(30); arr1.Add(40); arr1.Add(50);Now, let us set an array. The ... Read More

Remove duplicates from a List in C#

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 14:06:01

7K+ Views

Use the Distinct() method to remove duplicates from a list in C#.Firstly, add a new list −List arr1 = new List(); arr1.Add(10); arr1.Add(20); arr1.Add(30); arr1.Add(40); arr1.Add(50); arr1.Add(30); arr1.Add(40); arr1.Add(50);To remove duplicate elements, use the Distinct() method as shown below −List distinct = arr1.Distinct().ToList();Here is the complete code −Example Live Demousing System; ... Read More

C# Program to Subtract Two TimeSpan

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 14:04:46

429 Views

Firstly, set two TimeSpans −TimeSpan t1 = TimeSpan.FromMinutes(2); TimeSpan t2 = TimeSpan.FromMinutes(1);To add it, use the Subtract() method −imeSpan res = t1.Subtract(t2);Here is the complete code −Example Live Demousing System; using System.Linq; public class Demo {    public static void Main() {       TimeSpan t1 = TimeSpan.FromMinutes(2);     ... Read More

C# program to copy a range of bytes from one array to another

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 14:01:56

3K+ Views

Use the Buffer.BlockCopy method to copy a range of bytes from one array to another −Set a byte array −byte[] b1 = new byte[] {22, 49}; byte[] b2 = new byte[5];Copy bytes from one array to another −Buffer.BlockCopy(b1, 0, b2, 0, 2);The following is the complete code −Example Live Demousing System; ... Read More

Advertisements