- 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
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
550 Views
Firstly, use GetDrives to get the name of all the drives −var drv = DriveInfo.GetDrives();Loop through to get the name of all the drives on the system −foreach (DriveInfo dInfo in drv) { Console.WriteLine(dInfo.Name); }Let us see the complete code −Example Live Demousing System; using System.Linq; using System.IO; public class Demo { public static void Main() { var drv = DriveInfo.GetDrives(); foreach (DriveInfo dInfo in drv) { Console.WriteLine(dInfo.Name); } } }Output/etc/resolv.conf /etc/hostname /etc/hosts /run/secrets /home/cg/rootNote: The result will vary on different Operating Systems. The above ... Read More
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
201 Views
Use the DriveFormat property to get the drive format in C#.Set the drive for which you want to display the format −DriveInfo dInfo = new DriveInfo("C");Now, use DriveFormat to get the drive format −dInfo.DriveFormatThe drive formats for a windows system can be NTFS or FAT32.Here is the complete code −Exampleusing System; using System.Linq; using System.IO; public class Demo { public static void Main() { DriveInfo dInfo = new DriveInfo("C"); Console.WriteLine("Drive Format = "+dInfo.DriveFormat); } }OutputThe following is the output −Drive Format = NTFS
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
507 Views
Use the RootDirectory property to get the name of the root directory.Firstly, use DriveInfo to set the drive for which you want the root directory −DriveInfo dInfo = new DriveInfo("C");Now, the RootDirectory gives you the result −dInfo.RootDirectoryExampleHere is the complete code −using System; using System.Linq; using System.IO; public class Demo { public static void Main() { DriveInfo dInfo = new DriveInfo("C"); Console.WriteLine("Root Directory: "+dInfo.RootDirectory); } }OutputThe following is the output −C:\
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
146 Views
Set the drive for which you want to display the name −DriveInfo info = new DriveInfo("C");Now, to get the drive name, use the Name property −info.NameHere is the complete code with output −Exampleusing System; using System.Linq; using System.IO; public class Demo { public static void Main() { DriveInfo info = new DriveInfo("C"); Console.WriteLine(“Drive: “+info.Name); } }OutputThe following is the output −D:/
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
549 Views
To get the free space in a drive, use the AvailableFreeSpace and TotalFreeSpace properties in C#.Firstly, set the name of the drive using DriveInfo −DriveInfo dInfo = new DriveInfo("D");Let’s say, you need to find the available space for D drive −Exampleusing System; using System.Linq; using System.IO; public class Demo { public static void Main() { DriveInfo dInfo = new DriveInfo("D"); // Get free space Console.WriteLine(dInfo.AvailableFreeSpace); // get total free space Console.WriteLine(dInfo.TotalFreeSpace); } }OutputThe following is the output showing the free space available in D drive−722243567912 722243567912
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
1K+ Views
To display the last three elements from a list, use the Take() method. For reversing it, use the Reverse() method.Firstly, declare a list and add elements to it −List myList = new List(); myList.Add("One"); myList.Add("Two"); myList.Add("Three"); myList.Add("Four");Now, use the Take() method with Reverse() to display the last three elements from the list in reverse order −myList.Reverse().Take(3);The following is the code −Example Live Demousing System; using System.Linq; using System.Collections.Generic; public class Demo { public static void Main() { List myList = new List(); myList.Add("One"); myList.Add("Two"); myList.Add("Three"); ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
134 Views
Use the orderby leyword to sort a list in ascending or descending order.The following is the list −List myList = new List(); myList.Add("truck"); myList.Add("bus"); myList.Add("bicycle"); myList.Add("motorbike");Now let us sort the list in descending order −myLen = from element in myList orderby element.Length descending select element;Here is the complete code −Example Live Demousing System; using System.Collections.Generic; using System.Linq; class Demo { static void Main() { List myList = new List(); myList.Add("truck"); myList.Add("bus"); myList.Add("bicycle"); myList.Add("motorbike"); var myLen = from element in myList ... Read More
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
439 Views
The KeyNotFoundException is thrown when a key you are finding is not available in the Dictionary collection.Let us see an example −Example Live Demousing System; using System.Collections.Generic; public class Demo { public static void Main() { try { var dict = new Dictionary() { {"TV", "Electronics"}, {"Laptop", "Computers"}, }; Console.WriteLine(dict["Pen Drive"]); } catch (Exception e) { Console.WriteLine(e); } } ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
600 Views
Use the Sort method to sort the KeyValuePairs collection.Firstly, set the collection −var myList = new List(); // adding elements myList.Add(new KeyValuePair(1, 20)); myList.Add(new KeyValuePair(2, 15)); myList.Add(new KeyValuePair(3, 35)); myList.Add(new KeyValuePair(4, 50)); myList.Add(new KeyValuePair(5, 25));To sort, use the Sort() method. With that, we have used the CompareTo() method to compare values −myList.Sort((x, y) => (y.Value.CompareTo(x.Value)));The following is the complete code −Example Live Demousing System; using System.Collections.Generic; class Program { static void Main() { var myList = new List(); // adding elements myList.Add(new KeyValuePair(1, 20)); myList.Add(new KeyValuePair(2, 15)); ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
2K+ Views
Declare an array −int[] arr = { 5, 9, 2, 7 };Now to get the smallest element from an array, use the Min() method −arr.Min());Here is the complete code −Example Live Demousing System; using System.Linq; class Demo { static void Main() { int[] arr = { 5, 9, 2, 7 }; Console.WriteLine(arr.Min()); } }Output2