Samual Sam has Published 2492 Articles

IsNullOrWhiteSpace() Method in C#

Samual Sam

Samual Sam

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

2K+ Views

This method returns true if the entered string has only whitespace characters or is null.Let say you checked for null value −bool val1 = string.IsNullOrWhiteSpace(null);The above returns True, since the string is “null”. In the same way, check it for whitespace character.Here is the entire example that checks for null ... Read More

General Date Long Time ("G") Format Specifier in C#

Samual Sam

Samual Sam

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

177 Views

The General Date Long Time standard format specifier is a combination of the short date ("d") and long time ("T") patterns, separated by a space.Set the date −DateTime dt = new DateTime(2018, 1, 3, 3, 45, 20);Now, use the ToString() method and DateTimeFormatInfo.dt.ToString("G", DateTimeFormatInfo.InvariantInfo)Example Live Demousing System; using System.Globalization; class Demo ... Read More

Short Time ("t") Format Specifier in C#

Samual Sam

Samual Sam

Updated on 23-Jun-2020 07:03:57

319 Views

The Short Time format specifier represents a custom date and time format string.It is defined by the current DateTimeFormatInfo.ShortTimePattern property.For example, the custom format string is −HH:mmExample Live Demousing System; using System.Globalization; class Demo {    static void Main() {       DateTime date = new DateTime(2018, 5, 4, 10, ... Read More

Convert.ToDecimal Method in C#

Samual Sam

Samual Sam

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

3K+ Views

Convert a specified value to a decimal number using the Convert.ToDecimal() method.We have a string here.string stringVal = "2, 345.26";Now, let us use the Convert.ToDecimal() method to convert it to a decimal number.decimal decimalVal; decimalVal = System.Convert.ToDecimal(stringVal);Let us now see the complete example −Example Live Demousing System; public class Demo { ... Read More

Convert Decimal to Int64 (long) in C#

Samual Sam

Samual Sam

Updated on 23-Jun-2020 06:50:42

6K+ Views

Use the Convert.ToInt64() method to convert Decimal to Int64 (long) in C#.Let’s say we have a decimal variable.decimal d = 310.23m;Now to convert it to Int64, use the Convert.ToInt64() method.long res; res = Convert.ToInt64(d);Let us see another example −Example Live Demousing System; class Demo {    static void Main() {   ... Read More

C# Hexadecimal ("X") Format Specifier

Samual Sam

Samual Sam

Updated on 22-Jun-2020 15:39:09

6K+ Views

The hexadecimal ("X") format specifier is used to convert a number to a string of hexadecimal digits.Set the case of the format specifier for uppercase or lowercase characters to be worked on hexadecimal digits greater than 9.Let us understand this with an example −“X” for PQR, whereas “x” for pqrExample Live ... Read More

DirectoryNotFoundException in C#

Samual Sam

Samual Sam

Updated on 22-Jun-2020 15:32:08

694 Views

If a directory you are trying to find does not exist, then DirectoryNotFoundException occurs.Here, we are try to find a directory that does not exist using GetDirectories() method.Exampleusing System.IO; using System; class Program {    static void Main() {       Directory.GetDirectories("D:ew\");    } }The above code will generate ... Read More

C# ToTuple() Method

Samual Sam

Samual Sam

Updated on 22-Jun-2020 15:31:26

416 Views

Let’s say you have a ValueTuple and would like to convert it to a tuple, then use the ToTuple() method.With C#, we can easily convert a ValueTuple to a Tuple using ToTuple() method.Note − Add System.ValueTuple package to run ValueTuple program.Let’s see how to add it −Go to your projectRight ... Read More

Path methods in C#

Samual Sam

Samual Sam

Updated on 22-Jun-2020 15:29:06

193 Views

To handle File Paths in C#, use the Path methods. These methods come under System.IO Namespace.Some of them are −GetExtensionRetrieve the extension of the file using the GetExtension() method.For example, .txt, .dat, etc.GetFileNameRetrieve the name of the file using the GetFileName() method.For example, new.txt, details.dat, etc.GetFileNameWithoutExtensionRetrieve the name of the ... Read More

Convert a ValueTuple to a Tuple in C#

Samual Sam

Samual Sam

Updated on 22-Jun-2020 15:27:27

385 Views

With C#, we can easily convert a ValueTuple to a Tuple using ToTuple() method.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 ... Read More

Advertisements