Karthikeya Boyini has Published 2193 Articles

C# Program to merge sequences

karthikeya Boyini

karthikeya Boyini

Updated on 23-Jun-2020 07:32:51

203 Views

Let’s add two sequences.Integer Array.int[] intArray = { 1, 2, 3, 4, 5, 6, 7, 8 };String Array.string[] stringArray = { "Depp", "Cruise", "Pitt", "Clooney", "Sandler", "Affleck", "Tarantino" };Now to merge both the above sequences, use the Zip method.ntArray.AsQueryable().Zip(stringArray, (one, two) => one + " " + two);Let us see ... Read More

C# Program to check whether the elements of a sequence satisfy a condition or not

karthikeya Boyini

karthikeya Boyini

Updated on 23-Jun-2020 07:30:47

370 Views

Use All() Method to check whether the elements of a sequence satisfy a condition or not. Even if one of the element do not satisfy the set condition, the All() method returns False.To set conditions, use Lambda Expressions. Below shows a condition to check whether all the elements are greater ... Read More

C# General Date Short Time ("g") Format Specifier

karthikeya Boyini

karthikeya Boyini

Updated on 23-Jun-2020 07:28:58

402 Views

The Generate Date Short Time format specifier is a combination of the short date ("d") and short time ("t") patterns, separated by a space.Set a date using DateTime.DateTime dt = new DateTime(2018, 10, 2, 7, 59, 20);Now, use the (“g”) format specifier.dt.ToString("g", DateTimeFormatInfo.InvariantInfo));Example Live Demousing System; using System.Globalization; class Demo { ... Read More

C# Program to get the absolute value of the time

karthikeya Boyini

karthikeya Boyini

Updated on 23-Jun-2020 07:26:37

1K+ Views

To get the absolute value of time, use the TimesSpan Duration() method.Let’s say the following is our TimeSpan.TimeSpan ts = new TimeSpan(-7, -50, -25);Now to get the absolute value.TimeSpan duration = ts.Duration();Let us see the complete code.Example Live Demousing System; using System.Linq; public class Demo {    public static void Main() ... Read More

C# Percent ("P") Format Specifier

karthikeya Boyini

karthikeya Boyini

Updated on 23-Jun-2020 07:26:04

16K+ Views

The percent ("P") format specifier is used to multiply a number by 100.It converts the number into a string representing a % (percentage).We have the following double type −double val = .975746;If we will set (“P”) format specifier, then the above would result as −97.57 %In the same way, using ... Read More

C# Program to get the difference between two dates in seconds

karthikeya Boyini

karthikeya Boyini

Updated on 23-Jun-2020 07:22:16

6K+ Views

Set two dates.DateTime date1 = new DateTime(2018, 7, 15, 08, 15, 20); DateTime date2 = new DateTime(2018, 7, 15, 11, 14, 25);Now calculate the difference between two dates.TimeSpan ts = date2 - date1;Move further and calculate the difference in seconds.ts.TotalSecondsLet us see the complete code.Example Live Demousing System; using System.Linq; public ... Read More

Long Time ("T") Format Specifier in C#

karthikeya Boyini

karthikeya Boyini

Updated on 23-Jun-2020 07:19:46

465 Views

The Long Time format specifier represents a custom date and time format string.It is defined by DateTimeFormatInfo.LongTimePattern property.The custom format string.HH:mm:ssExample Live Demousing System; using System.Globalization; class Demo {    static void Main() {       DateTime date = new DateTime(2018, 9, 9, 8, 15, 30);       Console.WriteLine(date.ToString("T", ... Read More

C# Program to skip elements of an array from the end

karthikeya Boyini

karthikeya Boyini

Updated on 23-Jun-2020 07:18:00

1K+ Views

Declare an array and initialize elements.int[] marks = { 45, 50, 60, 70, 85 };Use the SkipLast() method to skip elements of an array from the end.IEnumerable selMarks = marks.AsQueryable().SkipLast(3);The elements are skipped and rest of the elements is returned as shown below −Example Live Demousing System; using System.Linq; using System.Collections.Generic; ... Read More

C# Exponential (“E”) Format Specifier

karthikeya Boyini

karthikeya Boyini

Updated on 23-Jun-2020 07:15:36

1K+ Views

The ("E") format specifier converts a number to a string of the following form −"-d.ddd…E+ddd"Or"-d.ddd…e+ddd"Above, "d" is a digit (0-9).Prefix the exponent with an "E" or an "e".Example Live Demousing System; using System.Globalization; class Demo {    static void Main() {       double d = 3452.7678;       ... Read More

C# Linq Where Method

karthikeya Boyini

karthikeya Boyini

Updated on 23-Jun-2020 07:13:44

3K+ Views

The Where method filters an array of values based on a predicate.Here, the predicate is checking for elements above 70.Where((n, index) => n >= 70);Example Live Demousing System; using System.Linq; using System.Collections.Generic; public class Demo {    public static void Main() {       int[] arr = { 10, 30, ... Read More

Advertisements