Tag: C#
How to Declare an Enumeration with Explicit Values in C# ?
There are times when you want to have a specific values to the enumeration to the enum items . For example , if you need to match particular values from the database or from a web service etc. How to Declare an Enumeration with Explicit Values in C# ? Below is a sample code snippet that demonstrates how to declare an enum with explicit values…
How to get the Names of all the columns from a SqlDataReader object in C# ?
Here’s a simple code snippet that demonstrates how to retreive all the column names from a SqlDataReader object in C#. How to get the Names of all the columns from a SqlDataReader object in C# ?
How to find if the Year is Leap Year or Not in C# ?
Below is a sample code snippet that demonstrates how to find if the year is a leap year or not. How to find if the Year is Leap Year or Not in C# ?
How to Find if the Number is a Power of 2 using Bitwise Operator in C# ?
If you need to find out if the number is a Power of 2 using BitWise Operator in C# , below is a sample code snippet that demonstrates how to do it. How to Find if the Number is a Power of 2 using Bitwise Operator in C# ?
Concatenate or Join a string Array using LINQ in C#
Want to join the items inside the string array say with, delimiter using LINQ in C#? It’s pretty easy. Below is a sample code snippet demonstrating in easy steps on how to concatenate a string array using LINQ in C#? Concatenate or Join a string Array using LINQ in C#
Example for Declarative vs. Imperative Style Code in C#
Are you looking out for an example of declarative vs imperative style code in c# ? . Below is a sample source code snippet that demonstrates the declarative vs. imperative code in C#. Example for Declarative vs. Imperative Style Code in C#
How to remove the non ascii characters from a string in C# ?
Regular expression comes in handy especially if you want to remove the non ascii characters from a string in C#. Here’s a regular expression sample in C# demonstrating how to do it. How to remove the non ascii characters from a string in C# ? The output of the code snippet will be cde in C#
Anonymous Type Example
The simplest example of the anonymous type is to use the var keyword and assign the non-null initial value to the variable declared with var keyword. Below is a sample soucrecode demonstrating the simple anonymous type example. The above code is similar to the code written like below.
How to Implement Interfaces in C# ?
Once the interface is created or available , you might want to implement the functionality of the interface in your class . How to Implement Interfaces in C# ? To implement an interface , we must declare and provide implementations for each functions in your class. Below is a sample code snippet that demonstrates how to implement interface in C#.
Single Line and Multi Line Comment Example in C#
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApplication1 { #region testregion public partial class Form1 : Form { // Single Line Comment Test public Form1() { InitializeComponent(); } /* This is a Multiline Comment test */ private void Form1_Load(object sender, EventArgs e) { Debug.WriteLine(“This is a test message”); } } #endregion…
What are Enumerations ?
Enumeration are like a group of integer constants where each of the symbols in the enumeration stands for an integer value starting from 0 (by default). You can create an Enum in C# with the keyword enum like the below example
How to Concatenate Array of Integers to a String in C# ?
Below is a sample code snippet demonstrating how to concatenate array of integers to a string in c#. How to Concatenate Array of Integers to a String in C# ?
How to Create Extension Method in C# ?
Extension methods are great way to add a method to an existing type . A typical scenario is when you dont have the access to the sourcecode and want to add a method to the type . How to Create Extension Method in C# ? Below is a sample code snippet that demonstrates how to create an extension method for the integer type to tell…
What is the Difference between String and String Builder in C#?
What is the Difference between String and String Builder in C#? The string instance is immutable i.e. each time when you change the string m a new instance is returned. This can be inefficient sometimes The StringBuilder allows the developers to have a mutable string. This is a good option in case you want to modify / append string many times.
How to Get the IP address in Winforms/Console Application using C#?
Below is a sample code snippet demonstrating in simple steps on how to retrieve the IP address in the Winforms or Console APPLICATION using c#. How to Get the IP address in Winforms/Console Application using C#?
How to Sort Array Elements in Ascending Order in C#?
The Array class includes static method called Sort which can be used to sort the array in ascending order in C#. Array.Sort(<arry>); How to Sort Array Elements in Ascending Order in C#? Below is a sample code snippet demonstrating sorting of array elements in ascending order in C#.
Number Formatting String (N) in C#
Below is a sample source code demonstrating the Number Formatting String (N) in C#.
Tools to Convert Java to C# Source Code
There are times when a developer would have done a project using Java and would want to reuse some of the data classes or business logic to C# for developing application on different platform. Tools to Convert Java to C# Source Code Below are some of the tools that can be used to convert the code from Java to C# . Sharpen This is a…
How to Get the Max Value from a List of Integer using LINQ Query in C#?
One of the easiest way to get the Max value from a List of Integer in C# is to use LINQ extension method. The LINQ in C# provide the Max method which can be used to retrieve the Max Value from the List. How to Get the Max Value from a List of Integer using LINQ Query in C#?