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…

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#

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 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 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#.

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…