Practical solutions

C# Howtos How-To Guides

Solve the problem. Keep building. Collection of C# how-to articles

Find the answer you need

Browse practical solutions, grouped by the task you're working on.

__COUNT__ entries on this page

How to Count Occurrences of a Character Inside a String in C#There are 3 main methods that can be used to calculate the number of occurrences of a character inside a string variable in C#, the linq method, the String.Split() function and the foreach loop. How to Compare Two Lists in C#There are 2 main methods that can be used to compare 2 lists for differences in C#, the Linq method and the List.Contains() functions. How to Slice An Array in C#There are 3 main methods that can be used to slice an array in C#, the Linq method, the ArraySegment class, and the extension function method. How to Print Array in C#There are 3 main methods that can be used to print an array of strings in C#, the String.Join() method, the ForEach() function, and the foreach loop method. How to Iterate Through a List in C#There are 3 main methods that can be used to iterate through a list in C#, the for loop, the foreach loop, and the Lambda expressions. How to Generate Random Alphanumeric Strings in C#There are 3 main methods that can be used to generate random alphanumeric strings in C#, the Random class, the LINQ method, and the RNGCryptoServiceProvider class. How to Exit Console Application in C#This article shows several methods that can be used to exit a console application in C#. How to Add String to an Array in C#There is no built-in method to dynamically add new elements to a completely filled array in C#. Final Keyword in C#There are 2 different keywords in C# that are equivalent to the final keyword in Java, the sealed keyword for classes and functions, and the readonly keyword for the fields. How to Get File Size in C#The FileInfo.Length property can be used to get the size of a file in C#. How to Download Image in C#There are 3 main methods that can be used to download an image in C#, the WebClient.DownloadFile() function, the Bitmap class, and the Image.FromStream() function. How to Create DataTable in C#The DataTable class can be used to create a data table in C#. How to Convert Object to Int in C#There are 3 main methods that can be used to convert an object to an integer variable in C#, the typecasting method, the int.Parse() function, and the Convert.ToInt32() function. How to Convert Int to Hex in C#The ToString() function can be used to convert an integer value to a hexadecimal string and the Convert.ToInt32() function can be used to convert a hexadecimal string to an integer value in C#. How to Initialize a List of Tuples in C#This article explores several approaches to efficiently initialize a list of tuples in C#. Abstract Function vs Virtual Function in C#An abstract function does not provide any definition of itself, while a virtual function has a default definition in C#. Thread vs Task in C#The Thread class creates an actual OS thread while the Task class creates a task that asynchronously executes in the thread pool. How to Write to the Output Window in C#There are 3 main methods that can be used to write to the debug window of the Microsoft Visual Studio IDE in C#, the Debug.Write(), the Debug.WriteLine(), and the Debug.Print() functions. How to Wait for a Thread to Finish in C#There are two main methods to wait for the completion of threads in C#, the Task.WaitAll() and the Thread.Join() functions. How to Remove First Character From String in C#There are two main methods that can be used to remove the first character from a string in C#, the String.Remove() method and the String.Substring() method. We can also achieve the same result using String Interpolation and LINQ. How to Pass Object by Reference in C#By default, all the value type variables are passed by value and all the reference type variables are passed by reference to a function in C#. How to Keep Console Open in C#There are 4 main methods that can be used to keep the console of visual studio IDE open in C#, the Console.ReadLine() method, the Console.Read() method, the Console.ReadKey() method, and the Ctrl + F5 shortcut. How to Get All File Names in a Directory in C#There are two main methods that can be used to get the file names of all the files inside a directory in C#, the Directory.GetFiles() function and the DirectoryInfo.GetFiles() function. How to Format a String to Currency in C#There are two main methods that can be used to format a string to currency format in C#, the String.Format() and the ToString() functions.