Tag: C#
How to Count the Number of 1 Bits in C# ?
Do you want to count the number of 1’s in a number in C# ? . Below is a sample source code that demonstrates how to count the number of 1 bits. How to Count the Number of 1 Bits in C# ?
How to generate a random number in C# and .NET?
If you want to generate a random number in your .NET application using C#, you can use the random class to generate one. How to generate a random number in C# and .NET? Below is a sample code snippet on how to generate random numbers in C#. Try to keep the instance of the Random class and reuse it Incase you are generating more than…
How to Convert a string in JSON.NET to XML in C# ?
You can use the JsonConvert.DeserializeXmlNode method of JSON.NET to convert from the json string to Xmldocument as shown below. How to Convert a string in JSON.NET to XML in C# ?
How to Print Leading Zeroes for a Number in C# ?
The Leading Zeroes for a number can be printed using the format string “D” in .NET . Below is a sample code snippet that demonstrates printing of 3 leading zeroes for a number 5 digit number in C#. How to Print Leading Zeroes for a Number in C# ?
How to compare two Byte Arrays in C#?
Are you looking to compare two array of bytes in C#? Below is a sample code snippet that demonstrates how to do it. How to compare two Byte Arrays in C#?
How to allow only numbers in a textbox in C# Windows Application ?
Want to allow the user to enter only numbers or integer values in a textbox in a C# Winforms Application ? . Below is a sample code snippet that demonstrates how to do it . How to allow only numbers in a textbox in C# Windows Application ? Assume that the text box name is “actxt” , we can map the Key Press event of…
How to mark a class as Obsolete or Deprecated in C# ?
Sometimes , you may want to mark a class or method as deprecated so that the you dont want to use the class any more and also want to let know , other developers that the class is obsolete . You can do that by using the Obsolete attribute as shown below . The Obsolete attribute also includes 2nd parameter (boolean) . When this valus…
How to Decode HTML Characters in C# ?
The .NET Framework 4.0 and above provides the WebUtility.HtmlDecode class which lets the developers to convert the string which are encoded with HTML characters to plain string . How to Decode HTML Characters in C# ? Below is a sample code snippet that demonstrates how to decode HTML characters in C#.
How to Create Comma Separated Strings from List of Strings in C#?
Below is a sample code snippet that demonstrates how one can easily create the comma separated strings from List<string> in C#. How to Create Comma Separated Strings from List of Strings in C#?
How to Use the Conditional Operator (?) in C# ?
Conditional Operator is also called as ternary operator which lets the developers to select between 2 values with a statement. Assume that you have to check for a number if it is even , we generally tend to use the if else statement . The same can be achieved using the ternary operator in C#. How to Use the Conditional Operator (?) in C# ?…
How to allow the user to browse for directories in Winforms App using C# ?
There are times when you want to allow the user to browse for files and select one in your Windows Application . The Winforms provides the FolderBrowserDialog class which can be used to select a file interactively. How to allow the user to browse for directories in Winforms App using C# ? Below is a sample code snippet demonstrating how to allow the user to…
How to Use the Null Coalescing Operator (??) in C# ?
There are times when you simply want to check if the value is null and perform some steps based on the condition . The Null Coalescing Operator (??) can help you achieve this. How to Use the Null Coalescing Operator (??) in C# ? Below is a sample code that uses Null Coalescing Operator (??) in C# to find if the vaklue is null ….