Karthikeya Boyini has Published 2193 Articles

Decimal constants in C#

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 14:48:39

3K+ Views

Decimal type has constants to get the minimum and maximum values.Set a decimal value −decimal d = 5.8M;To get the minimum and maximum values of the decimal type, use the following properties −decimal.MaxValue decimal.MinValueHere is the complete code −Example Live Demousing System; using System.Linq; class Demo {    static void Main() ... Read More

C# Program to get the last write time of a file

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 14:44:14

2K+ Views

To get the last write time of a file in C#, use the LastWriteTime() method.For this, use the FileInfo as well as DateTime classes.Create an object of each −FileInfo file = new FileInfo("amit.txt"); DateTime dt = file.CreationTime; dt = file.LastWriteTime;Let us see the complete code −Example Live Demousing System.IO; using System; ... Read More

Get the creation time of a file in C#

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 14:43:02

2K+ Views

To get the creation time of a file in C#, use the CreationTime() method.For this, use the FileInfo as well as DateTime classes.Create an object of each −FileInfo file = new FileInfo("new.txt"); DateTime dt = file.CreationTime;Let us see the complete code −Example Live Demousing System.IO; using System; public class Program { ... Read More

Literal number suffixes in C#

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 14:42:15

431 Views

To specify number types, use suffixes in C#. Literal number suffixes are numeric suffixes.For example, for long type −// long suffix long val1 = 29345L;For double type −// double suffix double val2 = 297.325D; Console.WriteLine(val2);Let us see more examples −Example Live Demousing System.IO; using System; public class Program {    public ... Read More

C# Program to skip initial elements in an array

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 14:41:15

3K+ Views

If you want to skip a number of elements in an array, then use the Skip() method in C#.Let’s say the following is our array −int[] arr = { 24, 40, 55, 62, 70, 82, 89, 93, 98 };Now to skip first four elements −var ele = arr.Skip(4);Let us see ... Read More

C# Program to find the largest element from an array using Lambda Expressions

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 14:39:54

617 Views

Declare an array −int[] arr = { 10, 90, 20, 19, 99, 57 };Now to get the largest element from an array, use Max() method with lambda expressions −arr.Max());Here is the complete code −Example Live Demousing System; using System.Linq; class Demo {    static void Main() {       int[] ... Read More

C# Program to combine Dictionary of two keys

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 14:38:25

868 Views

Firstly, set the Dictionaries to be combined −Dictionary dict1 = new Dictionary (); dict1.Add("one", 1); dict1.Add("Two", 2); Dictionary dict2 = new Dictionary (); dict2.Add("Three", 3); dict2.Add("Four", 4);Now, use HashSet to combine them. The method used for the same purpose is UnionWith() −HashSet hSet = new ... Read More

C# Program to count the number of lines in a file

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 14:37:06

2K+ Views

Firstly, create a file using StreamWriter class and add content to it −using (StreamWriter sw = new StreamWriter("hello.txt")) {    sw.WriteLine("This is demo line 1");    sw.WriteLine("This is demo line 2");    sw.WriteLine("This is demo line 3"); }Now use the ReadAllLines() method to read all the lines. With that, the ... Read More

C# Program to check whether a directory exists or not

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 14:35:49

280 Views

Use the Directory. Exists method to check whether a directory exists or not.Let’s say you need to check whether the following directory exists or not −C:\AmitFor that, use the Exists() method −if (Directory.Exists("C:\Amit")) {    Console.WriteLine("Directory Amit Exist!"); }The following is the complete code −Example Live Demousing System.IO; using System; public ... Read More

C# Program to create new directories

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 14:34:54

168 Views

Use the CreateDirectory method to create a directory.Let’s say you need to create a directory in D drive. For that, use the CreateDirectory() method as shown below −Directory.CreateDirectory("D:\Tutorial");The following is the code −Exampleusing System.IO; using System; public class Program {    public static void Main() {       Directory.CreateDirectory("D:\Tutorial"); ... Read More

Advertisements