C# DateTime Max Value

Chandu yadav
Updated on 23-Jun-2020 07:29:21

6K+ Views

To set the max value for a Date, use the DateTime property MaxValue.DateTime max = DateTime.MaxValue;Now, display the value of max to get the maximum value of a date as shown below.Example Live Demousing System; using System.Linq; public class Demo {    public static void Main() {       DateTime max = DateTime.MaxValue;       Console.WriteLine(max);    } }Output12/31/9999 11:59:59 PM

C# General Date Short Time G Format Specifier

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

425 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 {    static void Main() {       DateTime dt = new DateTime(2018, 10, 2, 7, 59, 20);       Console.WriteLine(dt.ToString("g", DateTimeFormatInfo.InvariantInfo));       Console.WriteLine(dt.ToString("g", CultureInfo.CreateSpecificCulture("en-us")));    } }Output10/02/2018 07:59 10/2/2018 7:59 AM

Return Specified Number of Elements from the End of an Array in C#

Arjun Thakur
Updated on 23-Jun-2020 07:28:31

230 Views

Use the TakeLast() method to return elements from the end of an array.Let us first declare and initialize an array.int[] prod = { 110, 290, 340, 540, 456, 698, 765, 789};Now, let’s get the last three elements.IEnumerable units = prod.AsQueryable().TakeLast(3);Let us see the complete code.Example Live Demousing System; using System.Linq; using System.Collections.Generic; public class Demo {    public static void Main() {       int[] prod = { 110, 290, 340, 540, 456, 698, 765, 789};       // value of last three products       IEnumerable units = prod.AsQueryable().TakeLast(3);       foreach (int res in units) {          Console.WriteLine(res);       }    } }Output698 765 789

C# TimeSpan Min Value

Samual Sam
Updated on 23-Jun-2020 07:27:41

562 Views

Timespan shows the length of time.To get the minimum value of TimeSpan, use the following property.TimeSpan.MinValueExample Live Demousing System; using System.Linq; public class Demo {    public static void Main() {       Console.WriteLine(TimeSpan.MinValue);    } }Output-10675199.02:48:05.4775808

Access Document Properties Using IE4 DOM Method

Smita Kapse
Updated on 23-Jun-2020 07:27:28

170 Views

This IE4 document object model (DOM) introduced in Version 4 of Microsoft's Internet Explorer browser. IE 5 and later versions include support for most basic W3C DOM features.ExampleTo access document properties using IE4 DOM method, try to run the following code −           Document Title                                     This is main title       Click the following to see the result:                                                                

C# TimeSpan Max Value

Ankith Reddy
Updated on 23-Jun-2020 07:27:05

1K+ Views

Timespan shows the length of time.To get the maximum value of TimeSpan, use the following property.TimeSpan.MaxValueExample Live Demousing System; using System.Linq; public class Demo {    public static void Main() {       Console.WriteLine(TimeSpan.MaxValue);    } }Output10675199.02:48:05.4775807

C# Program to Get the Absolute Value of Time

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() {       TimeSpan ts = new TimeSpan(-7, -50, -25);       TimeSpan duration = ts.Duration();       Console.WriteLine(duration);    } }Output07:50:25

C# %p Format Specifier

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 (“P1”), would only include a single vale after decimal-point.97.6%Example Live Demousing System; using System.Globalization; class Demo {    static void Main() {       double val = .975746;       Console.WriteLine(val.ToString("P", CultureInfo.InvariantCulture));       Console.WriteLine(val.ToString("P1", CultureInfo.InvariantCulture));       Console.WriteLine(val.ToString("P4", CultureInfo.InvariantCulture));    } }Output97.57 % 97.6 % 97.5746 %

Use W3C DOM or IE 4 DOM in a Script

Abhinanda Shri
Updated on 23-Jun-2020 07:25:37

158 Views

If you want to write a script with the flexibility to use either W3C DOM or IE 4 DOM depending on their availability, then you can use a capability-testing approach that first checks for the existence of a method or property to determine whether the browser has the capability you desire.The following is the code snippet showing the same −if (document.getElementById) {    // If the W3C method exists, use it } else if (document.all) {    // If the all[] array exists, use it } else {    // Otherwise use the legacy DOM }

C# Fixed-Point F Format Specifier

George John
Updated on 23-Jun-2020 07:25:28

1K+ Views

The ("F") format specifier converts a number to a string of the following form −"-ddd.ddd…"Above, "d" indicates a digit (0-9).Let us see an example.Here, if we will set (“F3”) format specifier to add three values after decimal places, for let’s say, 212.212.000The following is another example −Example Live Demousing System; using System.Globalization; class Demo {    static void Main() {       int val;       val = 38788;       Console.WriteLine(val.ToString("F",CultureInfo.InvariantCulture));       val = -344;       Console.WriteLine(val.ToString("F3",CultureInfo.InvariantCulture));       val = 5656;       Console.WriteLine(val.ToString("F5",CultureInfo.InvariantCulture));    } }Output38788.00 -344.000 5656.00000

Advertisements