- 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 34494 Articles for Programming
![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)
541 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)
133 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)
437 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
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
10K+ Views
The KeyValuePair class stores a pair of values in a single list with C#.Set KeyValuePair and add elements −var myList = new List(); // adding elements myList.Add(new KeyValuePair("Laptop", 20)); myList.Add(new KeyValuePair("Desktop", 40)); myList.Add(new KeyValuePair("Tablet", 60));Here is the code to learn how to work with KeyValuePair and display the keys and values −ExampleUsing System; using System.Collections.Generic; class Program { static void Main() { var myList = new List(); // adding elements myList.Add(new KeyValuePair("Laptop", 20)); myList.Add(new KeyValuePair("Desktop", 40)); myList.Add(new KeyValuePair("Tablet", 60)); foreach (var val in myList) { Console.WriteLine(val); } } }
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
12K+ Views
To convert a string to a long, use the Long.parse method in C# −Firstly, set a string −string str = "6987646475767";Now, convert it to long −long.Parse(str);Here is the complete code −Example Live Demousing System; using System.Linq; class Demo { static void Main() { string str = "6987646475767"; long res = long.Parse(str); Console.WriteLine(res); } }Output6987646475767
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
2K+ Views
To convert a string to a bool, use the Bool.parse method in C# −Firstly, set a string −string str = "false";Now, convert it to bool −bool.Parse(str);Here is the complete code −Example Live Demousing System; using System.Linq; class Demo { static void Main() { string str = "false"; bool res = bool.Parse(str); Console.WriteLine(res); } }OutputFalse