- 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
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
6K+ Views
To represent Int632as a Binary string in C#, use the ToString() method and set the base as the ToString() method’s second parameter i.e. 2 for Binary.Int32 represents a 32-bit signed integer.Firstly, set an Int64 variable −int val = 30;Now, convert it to a binary string by including 2 as the second parameter.Convert.ToString(val, 2)Example Live Demousing System; class Demo { static void Main() { int val = 30; Console.WriteLine("Integer: "+val); Console.Write("Binary String: "+Convert.ToString(val, 2)); } }OutputInteger: 30 Binary String: 11110
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
165 Views
Drive information of an Operating System includes.Drive Name Volume Label Free Space Total Size Drive Format Drive TypeTo get above information about a drive, try to run the following code −Exampleusing System.IO; using System; class Program { static void Main() { DriveInfo driveInfo = new DriveInfo("D"); Console.WriteLine(driveInfo.Name); Console.WriteLine(driveInfo.VolumeLabel); Console.WriteLine(driveInfo.AvailableFreeSpace); Console.WriteLine(driveInfo.TotalFreeSpace); Console.WriteLine(driveInfo.TotalSize); Console.WriteLine(driveInfo.DriveFormat); Console.WriteLine(driveInfo.DriveType); } }OutputThe following is the output −D: NTFS 76767677788 76767677788 45463434799 NTFS FixedNote − The output may vary with different Operating Systems.
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
7K+ Views
Let’s say the following is the string −StringBuilder str = new StringBuilder("Patience is key!");To remove whitespace, you can use the replace method.str.Replace(" ", "");Let us see the complete code.Example Live Demousing System; using System.Text; class Demo { static void Main() { // Initial String StringBuilder str = new StringBuilder("Patience is key!"); Console.WriteLine(str.ToString()); // Replace str.Replace(" ", ""); // New String Console.WriteLine(str.ToString()); Console.ReadLine(); } }OutputPatience is key! Patienceiskey!
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
193 Views
To handle File Paths in C#, use the Path methods. These methods come under System.IO Namespace.Some of them are −GetExtensionRetrieve the extension of the file using the GetExtension() method.For example, .txt, .dat, etc.GetFileNameRetrieve the name of the file using the GetFileName() method.For example, new.txt, details.dat, etc.GetFileNameWithoutExtensionRetrieve the name of the file without extension using the GetFileNameWithoutExtension() method.For example, new, details, etc.Let us see an example −Example Live Demousing System.IO; using System; class Program { static void Main() { string myPath = "D:\one.txt"; string fileExtension = Path.GetExtension(myPath); string fileName = Path.GetFileName(myPath); ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
2K+ Views
Set an array.int[] array = new int[] { 50, 100, 150, 200, 250, 300, 350, 400 };Now, if you will print this array using a loop and new line, then the arrays will be visible vertically.To work it horizontally, use the Join() method and set spaces to separate array elements.string.Join(" ", array)Let us see the complete code.Example Live Demousing System; using System.Linq; using System.IO; class Program { static void Main() { int[] array = new int[] { 50, 100, 150, 200, 250, 300, 350, 400 }; Console.WriteLine(string.Join(" ", array)); } }Output50 100 150 200 250 300 350 400
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
367 Views
Firstly, set a list and add elements.List myList = new List(); myList.Add("Jennings"); myList.Add("James"); myList.Add("Chris");Let’s say you need to delete the element “James” now. For that, use the Remove() method.myList.Remove("James");Here is the complete code.Example Live Demousing System.Collections.Generic; using System; class Program { static void Main() { List myList = new List(); myList.Add("Jennings"); myList.Add("James"); myList.Add("Chris"); Console.WriteLine("Initial List..."); foreach(string str in myList) { Console.WriteLine(str); } myList.Remove("James"); Console.WriteLine("New List..."); ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
416 Views
Let’s say you have a ValueTuple and would like to convert it to a tuple, then use the ToTuple() method.With C#, we can easily convert a ValueTuple to a Tuple using ToTuple() method.Note − Add System.ValueTuple package to run ValueTuple program.Let’s see how to add it −Go to your projectRight click on the project in the solution explorerSelect “Manage NuGet Packages”You will reach the NuGet Package Manager.Now, click the Browse tab and find “ValueTuple”Finally, add System.ValueTuple packageLet us see an example to implement ToTuple() method.Exampleusing System; class Program { static void Main() { var val = ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
223 Views
If a File you are trying to find does not exist, then FileNotFoundException occurs.Here, we are try to find a file that does not exist using StreamReader() method.reader = new StreamReader("new.txt"))To read it we have used the following method −reader.ReadToEnd();Let us see the complete code.Exampleusing System.IO; using System; class Program { static void Main() { using (StreamReader reader = new StreamReader("new.txt")) { reader.ReadToEnd(); } } }The above code will generate the following exception since the file “new.txt” does not exist.Unhandled Exception: System.IO.FileNotFoundException: Could not find file …
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
694 Views
If a directory you are trying to find does not exist, then DirectoryNotFoundException occurs.Here, we are try to find a directory that does not exist using GetDirectories() method.Exampleusing System.IO; using System; class Program { static void Main() { Directory.GetDirectories("D:ew\"); } }The above code will generate the following exception since the directory “D:ew” does not exist.Unhandled Exception: System.IO.DirectoryNotFoundException: Could not find a part of the path
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
3K+ Views
Declare an array and add elements.int[] val = { 5, 8, 15, 25, 40, 55, 80, 100 };Now, use the Queryable Last() method to get the last element.val.AsQueryable().Last();Let us see the complete code.Example Live Demousing System; using System.Collections.Generic; using System.Linq; class Demo { static void Main() { int[] val = { 5, 8, 15, 25, 40, 55, 80, 100 }; int last_num = val.AsQueryable().Last(); Console.WriteLine("Last element: "+last_num); } }OutputLast element: 100