C# Console WindowHeight Property

Samual Sam
Updated on 23-Jun-2020 07:22:58

234 Views

The WindowHeight property gets or sets the height of the console window.Declare a variable.int height;Now, get the height of the current window.height = Console.WindowHeight;The following is the complete example −Example Live Demousing System; using System.Numerics; using System.Globalization; class Demo {    static void Main() {       int height;       height = Console.WindowHeight;       Console.WriteLine("Current window height = "+height);    } }OutputCurrent window height = 0

Calculate Minutes Between Two Dates in C#

George John
Updated on 23-Jun-2020 07:22:38

21K+ Views

Firstly, set the two dates.DateTime date1 = new DateTime(2018, 7, 15, 08, 15, 20); DateTime date2 = new DateTime(2018, 8, 17, 11, 14, 25);Now, calculate the difference between two dates.TimeSpan ts = date2 - date1;To calculate minutes.ts.TotalMinutesLet 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 Minutes (Difference) = {0}", ts.TotalMinutes);    } }OutputNo. of Minutes (Difference) = 47699.0833333333

Document Properties Accessible Using Legacy DOM

Nishtha Thakur
Updated on 23-Jun-2020 07:22:35

140 Views

The following are the document properties which can be accessed using Legacy DOM −Sr.NoProperty & Description1alinkColorDeprecated − A string that specifies the color of activated links.Ex − document.alinkColor2anchors[ ]An array of Anchor objects, one for each anchor that appears in the documentEx − document.anchors[0], document.anchors[1] and so on3applets[ ]An array of Applet objects, one for each applet that appears in the documentEx − document.applets[0], document.applets[1] and so on4bgColorDeprecated − A string that specifies the background color of the document.Ex − document.bgColor5cookieA string-valued property with special behavior that allows the cookies associated with this document to be queried and set.Ex − ... Read More

Get the Difference Between Two Dates in Seconds using C#

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

7K+ 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 class Demo {    public static void Main() {       DateTime date1 = new DateTime(2018, 7, 15, 08, 15, 20);       DateTime date2 = new DateTime(2018, 7, 15, 11, 14, 25);       TimeSpan ts = date2 - date1;       Console.WriteLine("No. of Seconds (Difference) = {0}", ts.TotalSeconds);    } }OutputNo. of Seconds (Difference) = 10745

C# Console Window Left Property

Ankith Reddy
Updated on 23-Jun-2020 07:21:53

248 Views

The WindowsLeft property gets or sets the leftmost position of the console window area relative to the screen buffer.Declare an integer variable to get the leftmost position.int left;Now, use the Console.WindowLeft property.left = Console.WindowLeftLet us see the complete example.Example Live Demousing System; class Demo {    static void Main() {       int left;       left = Console.WindowLeft;       Console.WriteLine("Left position of the Console window = "+left);    } }OutputNote: The output may vary accordingly based on the position of the Console WindowLeft position of the Console window = 0

Role of Special Characters in JavaScript Regular Expressions

V Jyothi
Updated on 23-Jun-2020 07:21:43

287 Views

The frequency or position of bracketed character sequences and single characters can be denoted by a special character. Each special character has a specific connotation. The +, *, ?, and $ flags all follow a character sequence.Sr.NoExpression & Description1p+It matches any string containing one or more p's.2p*It matches any string containing zero or more p's.3p?It matches any string containing at most one p.4p{N}It matches any string containing a sequence of N p's5p{2, 3}It matches any string containing a sequence of two or three p's.6p{2, }It matches any string containing a sequence of at least two p's.7p$It matches any string with p ... Read More

Calculate Difference in Milliseconds Between Two DateTime

Samual Sam
Updated on 23-Jun-2020 07:21:31

8K+ Views

Let’s say the following are two DateTime objects for our dates.DateTime date1 = new DateTime(2018, 8, 11, 08, 15, 20); DateTime date2 = new DateTime(2018, 8, 11, 11, 14, 25);Find the difference between both these dates using TimeSpan.TimeSpan ts = date2 - date1;Now to get the Milliseconds, use the following property −ts.TotalMillisecondsLet us see the complete code.Example Live Demousing System; using System.Linq; public class Demo {    public static void Main() {       DateTime date1 = new DateTime(2018, 8, 11, 08, 15, 20);       DateTime date2 = new DateTime(2018, 8, 11, 11, 14, 25);       TimeSpan ts = date2 - date1;       Console.WriteLine("No. of Seconds (Difference) = {0}", ts.TotalMilliseconds);    } }OutputNo. of Seconds (Difference) = 10745000

Cast a Type to Its IEnumerable Equivalent in C#

Arjun Thakur
Updated on 23-Jun-2020 07:21:04

435 Views

Use the AsEnumerable() method to cast a type to its IEnumerable equivalent. It is an extension method.For our example, we have set an array.int[] myArr = new int[10]; myArr[0] = 1; myArr[1] = 2; myArr[2] = 3; myArr[3] = 4; myArr[4] = 5;Now, we have used the AsEnumerable() method to cast.myArr.AsEnumerable();Example Live Demousing System; using System.Linq; class Demo {    static void Main() {       int[] myArr = new int[10];       myArr[0] = 1;       myArr[1] = 2;       myArr[2] = 3;       myArr[3] = 4;       myArr[4] = 5;       myArr[5] = 6;       myArr[6] = 7;       myArr[7] = 8;       myArr[8] = 9;       myArr[9] = 10;       // AsEnumerable       var a = myArr.AsEnumerable();       // Displaying       foreach (var item in a) {          Console.WriteLine(item);       }    } }Output1 2 3 4 5 6 7 8 9 10

Check String for Whitespace Characters or Null in C#

Arjun Thakur
Updated on 23-Jun-2020 07:20:16

718 Views

This method returns true if the entered string has only whitespace characters or is null.Let’s say you are checking for whitespace character.bool val1 = string.IsNullOrWhiteSpace(“ “);The above returns True, since the string is a whitespace character. In the same way, check it for null using the IsNullOrWhiteSpace() method.Here is the entire example that checks for null and whitespace −Exampleusing System; using System.IO; public class Demo {    public static void Main() {       bool val1 = string.IsNullOrWhiteSpace(“100”);       bool val2 = string.IsNullOrWhiteSpace(" ");       bool val3 = string.IsNullOrWhiteSpace(null);       Console.WriteLine(val1);       Console.WriteLine(val2);       Console.WriteLine(val3);    } }

Long Time 'T' Format Specifier in C#

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

470 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", CultureInfo.CreateSpecificCulture("en-us")));    } }Output8:15:30 AM

Advertisements