Samual Sam has Published 2492 Articles

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

Samual Sam

Samual Sam

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

674 Views

To get the last access time of a file in C#, use the LastAccessTime() 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; dt = file.LastAccessTime;Let us see the complete code −Example Live Demousing System.IO; using System; ... Read More

Lowercase suffixes in C#

Samual Sam

Samual Sam

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

100 Views

Set lowercase suffixes for literals such as u, l, ul, f, etc.// l for long long a = 29876l;It can be used on literal numbers as well. It tells the compiler that the literal is of a specific type.The following is an example −Example Live Demousing System.IO; using System; public class ... Read More

ElementAt() method in C#

Samual Sam

Samual Sam

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

3K+ Views

ElementAt() is a System.Linq method in C# that is used to get and display element at a particular index.The following is our string array −string[] arr = { "One", "Two", "Three", "Four", "Five" };Now to get an element at index 0, use the ElementAt() method −arr.ElementAt(0);The following is the complete ... Read More

SkipWhile method in C#

Samual Sam

Samual Sam

Updated on 22-Jun-2020 14:40:31

284 Views

SkipWhile skips an element when a condition is matched.For example, use the following if you want to skip all even elements −ele => ele %2 == 0The following is an example wherein all the even elements are skipped and only the odd elements are displayed −Example Live Demousing System.IO; using System; ... Read More

C# Program to get the first three elements from a list

Samual Sam

Samual Sam

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

8K+ Views

Use the Take() method to get the first individual number of elements in C#.Firstly, set a list and add elements −List myList = new List(); myList.Add("One"); myList.Add("Two"); myList.Add("Three"); myList.Add("Four"); myList.Add("Five"); myList.Add("Six");Now, use the Take() method to get the elements from the list. Add the number of the elements you want ... Read More

ContainsValue in C#

Samual Sam

Samual Sam

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

71 Views

Use the ContainsValue() method in C# to search for a value in a Dictionary.Create a Dictionary and add elements −Dictionary d = new Dictionary(); d.Add("keyboard", "One"); d.Add("mouse", "Two");Now, use the ContainsValue() method to find a particular value −d.ContainsValue("Two");The following is the complete code −Example Live Demousing System; using System.Collections.Generic; using System.Linq; ... Read More

Case-insensitive Dictionary in C#

Samual Sam

Samual Sam

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

2K+ Views

To compare, ignoring case, use the case-insensitive Dictionary.While declaring a Dictionary, set the following property to get case-insensitive Dictionary −StringComparer.OrdinalIgnoreCaseAdd the property like this −Dictionary dict = new Dictionary (StringComparer.OrdinalIgnoreCase);Here is the complete code −Example Live Demousing System; using System.Collections.Generic; public class Program {    public static void Main() ... Read More

C# Program to write an array to a file

Samual Sam

Samual Sam

Updated on 22-Jun-2020 14:36:30

4K+ Views

Use WriteAllLines method to write an array to a file.Firstly, set a string array −string[] stringArray = new string[] {    "one",    "two",    "three" };Now, use the WriteAllLines method to add the above array to a file −File.WriteAllLines("new.txt", stringArray);Here is the complete code −Example Live Demousing System.IO; using System; ... Read More

C# Program to display the name of the directory

Samual Sam

Samual Sam

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

96 Views

Firstly, use the DirectoryInfo that operates on Directories. The parameter set in it is the file path −DirectoryInfo dir = new DirectoryInfo(@"D:ew\");To get the name of the directory, use the Name property −dir.NameThe following is the code to display the name of the directory −Example Live Demousing System.IO; using System; public ... Read More

C# Program to get information about a file

Samual Sam

Samual Sam

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

136 Views

To get information about a file means to get what all attributes are set for that particular file. For example, a file can be normal, hidden, archived, etc.Firstly, use the FileInfo class −FileInfo info = new FileInfo("hello.txt");Now, use FileAttributes to get information about a file −FileAttributes attr = info.Attributes;The following ... Read More

Advertisements