George John has Published 1167 Articles

C# Program to get the smallest and largest element from a list

George John

George John

Updated on 23-Jun-2020 07:09:34

8K+ Views

Set a list.List list = new List { 150, 300, 400, 350, 450, 550, 600 };To get the smallest element, use the Min() method.list.AsQueryable().Min();To get the largest element, use the Max() method.list.AsQueryable().Max();Let us see the complete code −Example Live Demousing System; using System.Collections.Generic; using System.Linq; class Demo {    static void ... Read More

Action Delegate in C#

George John

George John

Updated on 23-Jun-2020 07:03:31

184 Views

Action delegate does not return a value and can be used with a method that has a void return type.Declare Action Delegate.Action del = Display;Here is our method −public static void Display(int val) {    Console.WriteLine(val); }Now call the method with a value.Example Live Demousing System; public class Demo {   ... Read More

Nested Tuples in C#

George John

George John

Updated on 23-Jun-2020 06:55:41

507 Views

Let us first declare a nested tuple.var tuple = Tuple.Create(100, 200, 300, 400, 500, 600, Tuple.Create(720, 750, 780), 800 );Above, we added a nested tuple using Tuple.Create.Now to display elements in a nested tuple, nest the Item properties. Sine 7th item in the tuple is nested, we will be using ... Read More

Intersect two lists in C#

George John

George John

Updated on 22-Jun-2020 15:51:21

7K+ Views

Firstly, set two lists.List val1 = new List { 25, 30, 40, 60, 80, 95, 110 }; List val2 = new List { 27, 35, 40, 75, 95, 100, 110 };Now, use the Intersect() method to get the intersection between two lists.IEnumerable res = val1.AsQueryable().Intersect(val2);Example Live Demousing System; using System.Collections.Generic; using ... Read More

C# Aggregate() method

George John

George John

Updated on 22-Jun-2020 15:44:36

458 Views

The Aggregate() method applies an accumulator function over a sequence.The following is our array −string[] arr = { "DemoOne", "DemoTwo", "DemoThree", "DemoFour"};Now use the Aggregate() method. We have set the ssed value as “DemoFive” for comparison.string res = arr.AsQueryable().Aggregate("DemoFive", (longest, next) => next.Length > longest.Length ? next : longest, str ... Read More

C# Linq Distinct() Method

George John

George John

Updated on 22-Jun-2020 15:42:04

545 Views

To get the distinct elements, use the Distinct() method.The following is our list with duplicate elements.List points = new List { 5, 10, 5, 20, 30, 30, 40, 50, 60, 70 };Now to get the distinct elements −points.AsQueryable().Distinct();Let us see the entire example −Example Live Demousing System; using System.Linq; using System.Collections.Generic; ... Read More

Why is a Dictionary preferred over a Hashtable in C#?

George John

George John

Updated on 22-Jun-2020 15:36:35

177 Views

Hashtable class represents a collection of key-and-value pairs that are organized based on the hash code of the key. It uses the key to access the elements in the collection.Dictionary is a collection of keys and values in C#. Dictionary is included in the System.Collection.Generics namespace.Hashtable is slower than Dictionary. ... Read More

Role of CSS :last-child Selector

George John

George John

Updated on 22-Jun-2020 15:32:37

151 Views

Use the CSS :last-child selector to style every elements that is the last child of its parent. You can try to run the following code to implement the :last-child selectorLive Demo                    p:last-child {             background: orange;          }                     This is demo text1.       This is demo text2.       This is demo text3.    

EnumerateFiles method in C#

George John

George John

Updated on 22-Jun-2020 15:01:48

240 Views

EnumerateFile() method is used in C# to get all the files. Use AllDirectories property to recurse through directories −Directory.EnumerateFiles(@"D:\NEW", "*.*", SearchOption.AllDirectories)To get the list of files in a directory, use the SearchOptions.AllDirectories in C# as shown above.Let us see how −Exampleusing System; using System.IO; namespace Demo {    class Program ... Read More

Transform the element by using 16 values of matrix with CSS3

George John

George John

Updated on 22-Jun-2020 14:57:42

139 Views

Use the matrix3d(n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n) method to transform the element using 16 values of matrix.Let us see the syntaxmatrix3d(a1, b1, c1, d1, a2, b2, c2, d2, a3, b3, c3, d3, a4, b4, c4, d4)Here,  a1 b1 c1 ... Read More

Advertisements