Load Text from File to String variable using C#

In this example, we will show you how to load a text file into a string variable in C#. For this purpose, we are going to use the StreamReader.ReadToEnd method to read from a text file on your local machine, or on a network folder. First, you will need to add the namespace below: using... » read more

Convert HTML table to JSON string in ASP.NET using C# and JavaScript

In this tutorial, I will explain to you how to convert an HTML table to a JSON string using C#. Convert HTML table to JSON in ASP.NET To get started, insert a static table and an ASP button as shown in the code below: <table class="nav-justified" border="1" id="tblEmployees"> <tr> <td><strong>Name</strong></td> <td><strong>Department</strong></td> </tr> <tr> <td>Jeff</td> <td>IT</td>... » read more

Introduction to Delegate in C#

Delegate is a reference type variable that can hold the reference of a function. It is like a pointer to a method, in C++ or C. Delegates are implicitly driven from the System.Delegate Class. We can say that it is an object, or reference type variable, which refers to a function, and can hold the... » read more

Create HTML Table dynamically in ASP.NET using C#

In this example, we are going to show you how to create an HTML table dynamically in ASP.NET using C#. Create an HTML dynamically in ASP.NET For many reasons, a developer might need to create a table dynamically. For example, looping through a DataTable in order to print out the rows on the web page... » read more

Create a Global Error Handler in C# for a Console Application

It’s easy enough to handle the exception using try/catch blocks. Some application takes benefit of the global exception handler. For Example, if you want to control standard exceptions, you can use your custom global exception handler to handle exceptions such as divided by zero, ArrayOutOfBoundException etc. These exceptions may occur when an unhandled exception is found.... » read more

Check if a number is prime using C#

Below is a program in C# that check whether a number is prime or not. The program inputs a value form the user and print whether it is prime or not. What is a prime number? Every number is a prime number or a composite number except 0 and 1. A prime number is a... » read more

How to Swap Two Numbers using C#

Swapping of two numbers refers to the exchanging values of two variables. Here are two methods which we can use for swapping two integers Swap using a temporary variable Swap without using a temporary variable Swap two integer using a temporary variable This swap operation is performed by using a third variable (a temporary variable). Here... » read more

Check if a Year is Leap Year or Not using C#

There are 356 days in a common year while a leap year has 366 days. February 29 is a date Which occurs once after every four years and is called leap day. February 29 is included to the leap year calendar as leap day because the Earth does not complete its orbit around the sun... » read more

Filtering DataTable with Select Method using C#

DataTables are used to represent the data in a tabular format with several rows, columns, and constraints. There are several methods provided by the DataTable class for our easiness. Out of them, we will be talking about the Select() in this article. Select method is used to get the array of data of DataRow objects.... » read more

How to edit a row in a DataView using C#

DataViews are typically used in C# to represent a set of data obtained from the sources like a database or a dataTable from a different perspective. DataView often exposes several methods in sorting, searching and manipulating the data. In this example, we modify a row in an existing DataView with a new value. The dynamic... » read more

Bind an ADO.NET DataTable to a TreeView using C#

In this article, we are going to talk about the binding of datatable into a TreeView. For this, we’ll be using ADO.NET to create an instance of the database. Before getting into it, what is a TreeView? In simple terms, it is a graphical way of representing information in a hierarchical manner. It should have... » read more

Introduction to Numeric Functions in C#

From this article, we are going to talk about the different types of numeric/mathematical functions provided by C#. System namespace provides an inbuilt library to called Math, which provides a valuable set of methods for numeric calculations. As these methods are static methods, we don’t need to add any reference to it. These methods are... » read more

Calculate the difference between two dates using C#

In this article, we are going to look at how to calculate the date difference between two dates in C#. Like other OOP languages, C# has two data types to store the results. DateTime Structure TimeSpan Structure DateTime Struct DateTime Structure is a child of System namespace and no any other external libraries needed for... » read more