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 enumerate an enum in C#?
Below is a sample code snippet that demonstrates how to enumerate an enum in C# using Foreach statement? How to enumerate an enum in C#?
How to convert an Integer to Hexadecimal string in C# ?
You can easily format an integer to an Hexadecimal string in C# using the ToString() method. How to convert an Integer to Hexadecimal string in C# ? Below is a sample sourcecode that demonstrates How to convert an Integer to Hexadecimal string in C# ?
How to Convert Hexadecimal value to Decimal number in C# ?
Below is a sample sourecode demonstrating the conversion of the hexadecimal value to decimal number in c#. How to Convert Hexadecimal value to Decimal number 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# ?
@ Operator in C#
Although it is not the best practise , If you want use the reserve words and the variable name , you could use the @ prefixed before the variable name . Below is a sample sourcecode that demonstrates the use of @ symbol. static void Main() { int @if = 10; MessageBox.Show(@if.ToString()); }
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 find if the value is null for a Nullable Type in c# ?
The Nullable type in C# provides the property HasValue which can be used to find if the value is null . Below is a sample sourecode snippet demonstrating How to find if the value is null for a Nullable Type in c# ? How to find if the value is null for a Nullable Type 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 Combine URL in C#?
The .NET Framework includes the Path.Combine feature which can be used to combine the strings into a path. How about having the same functionality to combine URL? How to Combine URL in C#? This is where the Uri class comes handy. The Uri class includes the constructor which can be used to combine URL. For example, if I need to combine “http://www.abundantcode.com” and “blogs/article1.html”, I…
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 convert string to Int32 using System.Convert in C#?
Below is a sample code snippet demonstrating How to convert string to ToInt32 using System.Convert in C#
Character Escape Sequences in C#
Below are some list of the Character Escape Sequences available in C# \\ – Backslash \’ – Single quote \” – Double quote \b – Backspace \n – New line \r – Carriage return \t – Horizontal tab \f – Form feed \a – Alert \v – Vertical tab \0 – Null
How to check if the Character is a Letter in c# using Char.IsLetter ?
The Char.IsLetter function can be used to find if the character is a Letter (Unicode) . If the specified character is a Letter , then the function Char.IsLetter returns true else returns false. How to check if the Character is a Letter in c# using Char.IsLetter ? Below is a sample sourcecode demonstrated on how to use Char.IsLetter .
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#.
C# Keywords
Below are list of few Keywords in C# abstract as base break case catch checked class const continue default delegate do double else enum event explicit extern finally fixed for foreach goto if implicit in int interface internal is lock long namespace new null object operator out override params private protected public readonly ref return sbyte sealed short sizeof stackalloc static string struct switch this…
What is the difference between struct and class in C# ?
Below are some differences between struct and class in C# classes are reference types where as struct are value types. Null value cannot be assigned to the Struct because it is a non-nullable value type . Whereas the object of a class can be assigned a null value. Classes support inheritance but the struct doesn’t. struct cannot have destructor but a class can have. struct…
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#?