- 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 34490 Articles for Programming
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
4K+ Views
It lets you specify a block of code that you can expand or collapse when using the outlining feature of the Visual Studio Code Editor. It should be terminated with #endregion.Let us see how to define a region using #region.#region NewClass definition public class NewClass { static void Main() { } } #endregionThe following is an example showing the usage of #region directive.Example Live Demousing System; #region class MyClass { } #endregion class Demo { #region VARIABLE int a; #endregion static void Main() { #region BODY Console.WriteLine("Example showing the usage of region directive!"); #endregion } }OutputExample showing the usage of region directive!
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
177 Views
Hashtable class represents a collection of key-and-value pairs that are organized based on the hash code of the key. It uses the key to access the elements in the collection.Dictionary is a collection of keys and values in C#. Dictionary is included in the System.Collection.Generics namespace.Hashtable is slower than Dictionary. For strongly-typed collections, the Dictionary collection is faster.Let’s say we need to find a key from Hashtable collections. With that, we are also finding a key from Dictionary collection as well. In that case, Dictionary would be faster for the same statement −For HashTablehashtable.ContainsKey("12345");For Dictionarydictionary.ContainsKey("12345") Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
106 Views
With C# 7, you can easily create a ValueType with names.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 packageExampleusing System; class Program { static void Main() { var myTuple = (marks: 95, name: "jack", subject: "maths"); //Add System.ValueTuple package to run this program // using names to access Console.WriteLine("Student Marks: "+myTuple.marks); ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
501 Views
Firstly, set a string.StringBuilder str = new StringBuilder();Use Random.Random random = new Random((int)DateTime.Now.Ticks);Now loop through a number which is the length of the random string you want.for (int i = 0; i < 4; i++) { c = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65))); str.Append(c); }On every iteration above, a random character is generated and appended to form a string.The following is the complete example −Example Live Demousing System.Text; using System; class Program { static void Main() { StringBuilder str = new StringBuilder(); char c; Random random = new Random((int)DateTime.Now.Ticks); ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
7K+ Views
The hexadecimal ("X") format specifier is used to convert a number to a string of hexadecimal digits.Set the case of the format specifier for uppercase or lowercase characters to be worked on hexadecimal digits greater than 9.Let us understand this with an example −“X” for PQR, whereas “x” for pqrExample Live Demousing System; using System.Numerics; using System.Globalization; class Demo { static void Main() { int num; num = 345672832; Console.WriteLine(num.ToString("X")); Console.WriteLine(num.ToString("X2")); num = 0x307e; Console.WriteLine(num.ToString("x")); Console.WriteLine(num.ToString("X")); } }Output149A8C80 149A8C80 307e 307E
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
637 Views
This round-trip ("R") format specifier is supported for the Single, Double, and BigInteger types.It ensures that a numeric value converted to a string is parsed back into the same numeric value.Let us see an example −Firstly, we have a double variable.double doubleVal = 0.91234582637;Now, use the ToString() method: and set the Round-trip format specifier.doubleVal.ToString("R", CultureInfo.InvariantCulture);Let us see the complete example −Example Live Demousing System; using System.Numerics; using System.Globalization; class Demo { static void Main() { double doubleVal = 0.91234582637; string str = doubleVal.ToString("R", CultureInfo.InvariantCulture); double resRound = double.Parse(str, CultureInfo.InvariantCulture); ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
386 Views
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 packageExampleusing System; class Program { static void Main() { var val = (5, 50, 500, 5000); //Add System.ValueTuple package to run this program // ValueTuple Console.WriteLine(“ValueTuple: ” val); // Tuple Tuple myTuple = val.ToTuple(); Console.WriteLine(“Tuple: ”+myTuple); } }OutputValueTuple: (5, 50, 500, 5000) Tuple: (5, 50, 500, 5000)
![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!