Karthikeya Boyini has Published 2383 Articles

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

karthikeya Boyini

karthikeya Boyini

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

318 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

779 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

12K+ 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

5K+ 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

351 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

958 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

867 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

2K+ 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

Return the total elements in a sequence as a 64-bit signed integer in C#

karthikeya Boyini

karthikeya Boyini

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

60 Views

Firstly, set a string array.string[] num = { "One", "Two", "Three", "Four", "Five"};Use the Linq LongCount method to get the count of elements.num.AsQueryable().LongCount();Here is the complete code −Example Live Demousing System; using System.Collections.Generic; using System.Linq; class Demo {    static void Main() {       string[] num = { "One", ... Read More

Object Initializer in C#

karthikeya Boyini

karthikeya Boyini

Updated on 23-Jun-2020 07:06:25

129 Views

Initialize an object of a class with object initialize.Using it, you can assign values to the fields at the time of creating an object.We created Employee object and assigned values using curly bracket at the same time.Employee empDetails = new Employee() {    EID = 10,    EmpName = "Tim", ... Read More

Advertisements