Samual Sam has Published 2492 Articles

Convert.ToDateTime Method in C#

Samual Sam

Samual Sam

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

721 Views

The Convert.ToDateTime method converts a given value to a DateTime value.The following is my string.string myDateString; myDateString = "09/09/2018";Now, let us convert it using the Convert.ToDateTime() method.DateTime result; result = Convert.ToDateTime(myDateString);Here is the complete example.Example Live Demousing System; public class Demo {    public static void Main() {       ... Read More

C# Program to invert the order of elements in a sequence

Samual Sam

Samual Sam

Updated on 23-Jun-2020 07:31:48

137 Views

Set a string.char[] ch = { 'd', 'r', 'i', 'v', 'e' }; Console.Write("String = foreach(char arr in ch) Console.Write(arr);Now, use Queryable Reverse() method to invert the order of elements.IQueryable res = ch.AsQueryable().Reverse();Let us see the complete code.Example Live Demousing System; using System.Linq; using System.Collections.Generic; public class Demo {    public static ... Read More

How to initialize an empty DateTime in C#

Samual Sam

Samual Sam

Updated on 23-Jun-2020 07:30:24

2K+ Views

Set a DateTime to its minimum value.DateTime.MinValue;The above will display the minimum value i.e.1/1/0001Let us see how to display the minimum value and avoid adding null to a date to initialize it as empty.Example Live Demousing System; using System.Linq; public class Demo {    public static void Main() {     ... Read More

C# TimeSpan Min value

Samual Sam

Samual Sam

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

372 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

C# Program to determine the difference in hours between two dates

Samual Sam

Samual Sam

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

9K+ 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 ... Read More

C# Console.WindowHeight Property

Samual Sam

Samual Sam

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

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

C# difference in milliseconds between two DateTime

Samual Sam

Samual Sam

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

6K+ 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 ... Read More

Convert.ToSingle Method in C#

Samual Sam

Samual Sam

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

838 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 ... Read More

Implicit conversion from 64-bit signed integer (long) to Decimal in C#

Samual Sam

Samual Sam

Updated on 23-Jun-2020 07:17:31

191 Views

The long type represents a 64-bit signed integer.To implicitly convert a 64-bit signed integer to a Decimal, firstly set a long value.long val = 989678876876876;To convert long to decimal, assign the value.dec = val;Let us see another example −Example Live Demousing System; public class Demo {    public static void Main() ... Read More

C# Program to make a copy of an existing file

Samual Sam

Samual Sam

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

755 Views

Use File.Copy method to make copy of an existing file.Add the path of the file you want to copy.String myPath = @"D:\one.txt";Now copy the above file to the following file −String myPath = @"D:\one.txt";Use the File.Copy method with both the source and destination file.File.Copy(myPath, newpath);Exampleusing System; using System.IO; public class ... Read More

Advertisements