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

146 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

Role of Throw Statement in JavaScript

Jennifer Nicholas
Updated on 23-Jun-2020 07:25:09

184 Views

Use the throw statement to raise your built-in exceptions or your customized exceptions. Later these exceptions can be captured and you can take appropriate action.ExampleYou can try to run the following code to implement throw statement −                                         Click the following to see the result:                          

Add Node After Given Node in Linked List using C#

Chandu yadav
Updated on 23-Jun-2020 07:24:57

318 Views

Set a LinkedList and add elements.string [] students = {"Beth", "Jennifer", "Amy", "Vera"}; LinkedList list = new LinkedList(students);Firstly, add a new node at the end.var newNode = list.AddLast("Emma");Now, use the AddAfter() method to add a node after the given node.list.AddAfter(newNode, "Matt");The following is the complete code.Example Live Demousing System; using System.Collections.Generic; class Demo {    static void Main() {       string [] students = {"Beth", "Jennifer", "Amy", "Vera"};       LinkedList list = new LinkedList(students);       foreach (var stu in list) {          Console.WriteLine(stu);       }       // ... Read More

Access Document Properties Using Legacy DOM Method in JavaScript

Srinivas Gorla
Updated on 23-Jun-2020 07:24:34

191 Views

To access document properties using Legacy DOM method in JavaScript, you can try to run the following code −Example           Document Title                                     This is main title       Click the following to see the result:                                                        

Determine Difference in Hours Between Two Dates in C#

Samual Sam
Updated on 23-Jun-2020 07:24:08

11K+ Views

Set two dates.DateTime date1 = new DateTime(2018, 7, 15, 08, 15, 20); DateTime date2 = new DateTime(2018, 8, 17, 11, 14, 25);Now, get the difference between two dates.TimeSpan ts = date2 - date1;Get the result i.e. the difference in hours.ts.TotalHoursLet us see the complete code.Example Live Demousing System; using System.Linq; public class Demo {    public static void Main() {       DateTime date1 = new DateTime(2018, 7, 15, 08, 15, 20);       DateTime date2 = new DateTime(2018, 8, 17, 11, 14, 25);       TimeSpan ts = date2 - date1;       Console.WriteLine("No. of Hours (Difference) = {0}", ts.TotalHours);    } }OutputNo. of Hours (Difference) = 794.984722222222

How Objects are Organized in a Web Document

Anvi Jain
Updated on 23-Jun-2020 07:24:03

250 Views

The Objects are organized in a hierarchy. This hierarchical structure applies to the organization of objects in a Web document.Window object − Top of the hierarchy. It is the utmost element of the object hierarchy.Document object − Each HTML document that gets loaded into a window becomes a document object. The document contains the contents of the page.Form object − Everything enclosed in the ... tags sets the form object.Form control elements − The form object contains all the elements defined for that object such as text fields, buttons, radio buttons, and checkboxes.The following is a simple hierarchy of a ... Read More

Document Methods Supported by Legacy DOM

Priya Pallavi
Updated on 23-Jun-2020 07:23:30

134 Views

The following is the list of document methods supported by Legacy DOM −Sr.NoProperty & Description1clear( )Deprecated − Erases the contents of the document and returns nothing.Ex − document.clear( )2close( )Closes a document stream opened with the open( ) method and returns nothing.Ex − document.close( )3open( )Deletes existing document content and opens a stream to which new document contents may be written. Returns nothing.Ex − document.open( )4write( value, ...)Inserts the specified string or strings into the document currently being parsed or appends to document opened with open( ). Returns nothing.Ex − document.write( value, ...)5writeln( value, ...)Identical to write( ), except that ... Read More

Advertisements