- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 34486 Articles for Programming
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
274 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 static void Main() { // long suffix long val1 = 29345L; Console.WriteLine(val1); // decimal suffix decimal val5 = 3245.5678M; Console.WriteLine(val5); // double suffix double val2 = 297.325D; Console.WriteLine(val2); // float suffix float val3 = 250.35F; Console.WriteLine(val3); // unsigned suffix uint val4 = 3456U; Console.WriteLine(val4); } }Output29345 3245.5678 297.325 250.35 3456
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
101 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 Program { public static void Main() { long a = 29876l; float b = 95.10f; Console.WriteLine(a); Console.WriteLine(b); } }On running the above example, you will get the following output. With that, you will also get a ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
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 { public static void Main() { using (StreamWriter sw = new StreamWriter("qa.txt")) { sw.WriteLine("Questions and Answers!"); } FileInfo file = new FileInfo("qa.txt"); // file creation time DateTime dt = file.CreationTime; Console.WriteLine(dt); } }Output9/5/2018 5:20:03 AM
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
675 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; public class Program { public static void Main() { using (StreamWriter sw = new StreamWriter("quiz.txt")) { sw.WriteLine("Quizzes!"); } FileInfo file = new FileInfo("quiz.txt"); // last access time DateTime dt = file.LastAccessTime; Console.WriteLine(dt); } }Output9/5/2018 5:21:43 AM
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
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; public class Program { public static void Main() { using (StreamWriter sw = new StreamWriter("amit.txt")) { sw.WriteLine("Welcome!"); } FileInfo file = new FileInfo("amit.txt"); // file creation time DateTime dt = ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
137 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 is the code −Example Live Demousing System.IO; using System; public class Program { public static void Main() { using (StreamWriter sw = new StreamWriter("hello.txt")) { sw.WriteLine("This is demo text!"); } FileInfo info = new FileInfo("hello.txt"); FileAttributes attr = info.Attributes; Console.WriteLine(attr); } }OutputNormal
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
108 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"); } }
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
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 class Program { public static void Main() { DirectoryInfo dir = new DirectoryInfo(@"D:ew\"); // displaying the name of the directory Console.WriteLine(dir.Name); } }OutputD:ew\
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
186 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 class Program { public static void Main() { if (Directory.Exists("C:\Amit")) { Console.WriteLine("Directory Amit Exist!"); } else { Console.WriteLine("Directory Amit does not exist!"); } } }OutputDirectory Amit does not exist!
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
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; public class Program { public static void Main() { string[] stringArray = new string[] { "one", "two", "three" }; File.WriteAllLines("new.txt", stringArray); using (StreamReader sr = new StreamReader("new.txt")) { string res = sr.ReadToEnd(); Console.WriteLine(res); } } }Outputone two three