C# Console Window Left Property

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

260 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

300 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

446 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

733 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

483 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

Full Date and Short Time Format Specifier in C#

Ankith Reddy
Updated on 23-Jun-2020 07:19:26

222 Views

The Full Date Short Time standard format specifier represents a combination of the long date ("D") and short time ("t") patterns.UseDateTime to set the date.DateTime myDate = new DateTime(2018, 8, 29, 1, 10, 0);Now, use the (“f”) format specifier like this −myDate.ToString("f", CultureInfo.CreateSpecificCulture("en-US"))The following is an example −Example Live Demousing System; using System.Globalization; class Demo {    static void Main() {       DateTime myDate = new DateTime(2018, 8, 29, 1, 10, 0);       Console.WriteLine(myDate.ToString("f",CultureInfo.CreateSpecificCulture("en-US")));    } }OutputWednesday, August 29, 2018 1:10 AM

Convert toSingle Method in C#

Samual Sam
Updated on 23-Jun-2020 07:19:07

2K+ Views

Convert a specified value to a single-precision floating-point number using the Convert.ToSingle() method in C#.Here is our bool −bool boolVal = false;Now, let us use the ToSingle() method to convert the value to a single precision floating-point.float floatVal; floatVal = Convert.ToSingle(boolVal);Example Live Demousing System; public class Demo {    public static void Main() {       bool boolVal = false;       float floatVal;       floatVal = Convert.ToSingle(boolVal);       Console.WriteLine("Converted {0} to {1}", boolVal, floatVal);    } }OutputConverted False to 0

Add Days to Current Date in C#

George John
Updated on 23-Jun-2020 07:18:39

7K+ Views

Firstly, get the current date.DateTime.TodayNow, use AddDays() method to add days to the current date. Here, we are adding 10 days to the current date.DateTime.Today.AddDays(10)Let us see the complete code −Example Live Demousing System; using System.Linq; public class Demo {    public static void Main() {       Console.WriteLine("Today = {0}", DateTime.Today);       Console.WriteLine("Add 10 Days = {0}", DateTime.Today.AddDays(10));    } }OutputToday = 9/11/2018 12:00:00 AM Add 10 Days = 9/21/2018 12:00:00 AM

Skip Elements of an Array from the End in C#

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; public class Demo {    public static void Main() {       int[] marks = { 45, 50, 60, 70, 85 };       Console.WriteLine("Array...");       foreach (int res in marks)       Console.WriteLine(res);       IEnumerable selMarks = marks.AsQueryable().SkipLast(3);       Console.WriteLine("Array after skipping last 3 elements...");       foreach (int res in selMarks)       Console.WriteLine(res);    } }OutputArray... 45 50 60 70 85 Array after skipping last 3 elements... 45 50

Advertisements