Samual Sam has Published 2492 Articles

Sort list elements in descending order in C#

Samual Sam

Samual Sam

Updated on 23-Jun-2020 08:24:22

779 Views

The following is our list with elements −IList emp = new List() {    new Employee() { EmployeeRank = 4, EmpName = "Amit", EmpMarks = 90 } ,    new Employee() { EmployeeRank = 05, EmpName = "Raman", EmpMarks = 95 } };Now use orderby and descending to sort elements ... Read More

Full Date Long Time ("F") Format Specifier in C#

Samual Sam

Samual Sam

Updated on 23-Jun-2020 08:22:05

157 Views

The Full Date Long Time standard format specifier’s custom date and time format string is defined by the current DateTimeFormatInfo.FullDateTimePattern property.The custom format string is −dddd, dd MMMM yyyy HH:mm:ssExample Live Demousing System; using System.Globalization; class Demo {    static void Main() {       DateTime myDate = new DateTime(2018, ... Read More

C# Program to find the cube of elements in a list

Samual Sam

Samual Sam

Updated on 23-Jun-2020 08:20:38

423 Views

Use Select method and Lambda Expression to calculate the cube of elements.The following is our list.List list = new List { 2, 4, 5, 7 };Now, use the Select() method and calculate the cube.list.AsQueryable().Select(c => c * c * c);The following is the entire example.Example Live Demousing System; using System.Linq; using ... Read More

AsEnumerable() in C#

Samual Sam

Samual Sam

Updated on 23-Jun-2020 08:19:39

4K+ Views

To cast a specific type to its IEnumerable equivalent, use the AsEnumerable() method. It is an extension method.The following is our array −int[] arr = new int[5]; arr[0] = 10; arr[1] = 20; arr[2] = 30; arr[3] = 40; arr[4] = 50;Now, get the IEnumerable equivalent.arr.AsEnumerable();Example Live Demousing System; using System.Linq; ... Read More

C# Regex. Matches Method

Samual Sam

Samual Sam

Updated on 23-Jun-2020 08:16:49

1K+ Views

The method matches instances of a pattern and is used to extract value based on a pattern.Let us see hoe to check for a valid URL.For that, pass the regex expression in the Matches method.MatchCollection mc = Regex.Matches(text, expr);Above, the expr is our expression that we have set to check ... Read More

Convert.ToDouble Method in C#

Samual Sam

Samual Sam

Updated on 23-Jun-2020 08:12:13

8K+ Views

To convert a specified value to a double-precision floating-point number, use Convert.ToDouble() method.The following is our long value −long[] val = { 340, -200};Now convert it to Double.double result; result = Convert.ToDouble(val);Example Live Demousing System; public class Demo {    public static void Main() {       long[] val = ... Read More

How to return the number of images in a document with JavaScript?

Samual Sam

Samual Sam

Updated on 23-Jun-2020 08:12:05

869 Views

To return the number of images in a document, use the images property in JavaScript.ExampleYou can try to run the following code to get the count of images −Live Demo                                            var val = document.images.length;          document.write("Number of images in the document: "+val);          

C# Program to access first element in a Dictionary

Samual Sam

Samual Sam

Updated on 23-Jun-2020 08:09:48

3K+ Views

The following is our Dictionary with some elements −Dictionary d = new Dictionary() {    {1, "Electronics"},    {2, "Clothing"},    {3, "Toys"},    {4, "Footwear"},    {5, "Accessories"} };Now to display the first element, set the key like this.d[1];The above displays the first element.Example Live Demousing System; using System.Collections.Generic; public ... Read More

Short Date ("d") Format Specifier

Samual Sam

Samual Sam

Updated on 23-Jun-2020 08:07:54

210 Views

The "d" format specifier represents a custom date and time format string.The format string is defined by culture's DateTimeFormatInfo.ShortDatePattern property.The custom format string is −MM/dd/yyyyExample Live Demousing System; using System.Globalization; class Demo {    static void Main() {       DateTime myDate = new DateTime(2018, 9, 09);       ... Read More

The "%" custom specifier in C#

Samual Sam

Samual Sam

Updated on 23-Jun-2020 08:06:03

126 Views

A % in a format string would multiply a number by 100 before it is formatted.The percent symbol is added in the number at the location where the % appears.For an example, declare and initialize a double variable.double d = .045;Now, use % custom specifier to multiply number by 100.d.ToString("#0.##%", ... Read More

Advertisements