Ankith Reddy has Published 1070 Articles

C# TimeSpan Max value

Ankith Reddy

Ankith Reddy

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

658 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# Console.WindowLeft Property

Ankith Reddy

Ankith Reddy

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

173 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() {   ... Read More

Full Date Short Time ("f") Format Specifier in C#

Ankith Reddy

Ankith Reddy

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

133 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; ... Read More

Delete a file in C#

Ankith Reddy

Ankith Reddy

Updated on 23-Jun-2020 07:12:15

711 Views

Use File.Delete method to delete a file.Firstly, set the path of the file you want to delete.String myPath = @"C:\New\amit.txt";Now, use the File.Delete method to delete the file.File.Delete(myPath);The following is the complete code −Example Live Demousing System; using System.IO; public class Program {    public static void Main() {     ... Read More

Collection Initialization in C#

Ankith Reddy

Ankith Reddy

Updated on 23-Jun-2020 07:04:32

682 Views

Initialize Collection like class objects using collection initializer syntax.Firstly, set values for the Employee object −var emp1 = new Employee() { EID = 001, EmpName = "Tim", EmpDept = "Finance"}; var emp2 = new Employee() { EID = 002, EmpName = "Tom", EmpDept = "HR"};Now add this under a collection.IList ... Read More

Join, Sleep and Abort methods in C# Threading

Ankith Reddy

Ankith Reddy

Updated on 23-Jun-2020 06:58:34

384 Views

JoinBlocks the calling thread until a thread terminates, while continuing to perform standard COM and SendMessage pumping. This method has different overloaded forms.SleepMakes the thread pause for a period of time.AbortThe Abort method is used to destroy threads.Let us see an example of Join() in threading −Exampleusing System; using System.Diagnostics; ... Read More

C# Program to display the first element from an array

Ankith Reddy

Ankith Reddy

Updated on 23-Jun-2020 06:51:22

2K+ Views

The following is our array −double[] myArr = {20.5, 35.6, 45.7, 55.6, 79.7};To get the first element, use the First() method.myArr.AsQueryable().First();Let us see the complete code −Example Live Demousing System; using System.Linq; using System.Collections.Generic; class Demo {    static void Main() {       double[] myArr = {20.5, 35.6, 45.7, ... Read More

Enumerable.Repeat method in C#

Ankith Reddy

Ankith Reddy

Updated on 22-Jun-2020 15:45:10

2K+ Views

Enumerable.Repeat method is part of System.Linq namespace.It returns a collection with repeated elements in C#.Firstly, set which element you want to repeat and how many times.As an example, let us see how to repeat number 10, five times −Enumerable.Repeat(10, 5);The following is the complete example −Example Live Demousing System; using System.Linq; ... Read More

Remove all duplicates from a given string in C#

Ankith Reddy

Ankith Reddy

Updated on 22-Jun-2020 15:43:10

317 Views

Here is the string.string str = "ppqqrr";Now, use Hashset to map the string to char. This will remove the duplicate characters from a string.var res = new HashSet(str);Let us see the complete example −Example Live Demousing System; using System.Linq; using System.Collections.Generic; namespace Demo {    class Program {       ... Read More

C# program to create a ValueType with names

Ankith Reddy

Ankith Reddy

Updated on 22-Jun-2020 15:35:11

106 Views

With C# 7, you can easily create a ValueType with names.Note − Add System.ValueTuple package to run ValueTuple program.Let’s see how to add it −Go to your projectRight click on the project in the solution explorerSelect “Manage NuGet Packages”You will reach the NuGet Package Manager.Now, click the Browse tab and ... Read More

Advertisements