Author

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

Check if a Number is valid using Java

Below is a snippet to check if a number  is valid or not. For example, the string “1.1.1” contains an invalid number, while the string “2.1” contains a valid number. The Code public class Main { public static void main (String[]args) { int i; System.out.println("Enter a Number:"); String str = System.console().readLine (); try { Double.parseDouble(str);... » read more

Pass DataTable from Controller to View in ASP.Net MVC

In this article, you are going to learn how to pass a DataTable from a controller to a razor view in ASP.NET MVC. The table passed will be displayed on the view page. Pass DataTable from Controller to View To get started, let’s create a database table like the following: CREATE TABLE [dbo].[Novel]( [NovelID] [int]... » read more

Retrieve Items from a LinkedList in Java

Here is another Java snippet that can help to enhance your program by using LinkedLists. The code below will retrieve all items from a linkedList and print them one by one to the console. class Main { public static void main(String[] args) { java.util.LinkedList<String> employees = new java.util.LinkedList<String>(); employees.add("Scott"); employees.add("Marie"); employees.add("Dun"); for (String string :... » read more

Calculate the average of array element using Java

Below is a program that calculates the average value of an array using Java. public static void main(String[] args) { int[] arr= new int[]{1,2,3,4,5}; int sum = 0; for(int count=0; count < arr.length ; count++) sum = sum + arr[count]; double average = sum / arr.length; System.out.println("The average value of the array elements is :... » read more

Get the sum of array element using Java

Here is a program in Java that sums up all array element and print out the result to the console. class Main { public static void main(String[] args) { int[] arr = {1,2,3,4,5}; int total = 0; for (int i = 0; i < arr.length; i++) total += arr[i]; System.out.printf("The sum of array elements is:... » read more

Get List of Installed Windows Services using C#

Below is a program that will return all installed Windows Services on a local machine. The program uses the namespace System.ServiceProcess, which can be used by adding the Assemblies System.ServiceProcess.dll static void Main(string[] args) { System.ServiceProcess.ServiceController[] services = System.ServiceProcess.ServiceController.GetServices(); foreach (System.ServiceProcess.ServiceController service in services) { Console.WriteLine(service.ServiceName); } Console.ReadKey(); } Happy Coding! More C# Snippets

Get the square root of a number using Java

Square root can be easily obtained in Java by using the Math.sqrt function. The Math is a class in Java that contains methods that allows you to perform mathematical operations. System.out.println(Math.sqrt(9)); Result 3 More Java Snippets

Create a new Thread Delegate using C#

Below is a code that demonstrates how to create a Thread Delegate, which calls a function that will do some work for you in the background. static void Main(string[] args) { // Creating a thread Delegate System.Threading.Thread _thread = new System.Threading.Thread(new System.Threading.ThreadStart(FuctionDoBackgroundWork)); _thread.Start(); } // Fucntion that the thread delegate Starts public static void FuctionDoBackgroundWork()... » read more

Validate Email Address using PHP

Below is a PHP function that validates an email address and returns the result as a boolean. This function uses the PHP built-in function filter_var and the filter FILTER_VALIDATE_EMAIL <?php //php 7.0.8 function ValidateEmail($email) { $email = '[email protected]'; $isValid = filter_var($email, FILTER_VALIDATE_EMAIL); if ($isValid) { return true; } else { return false; } } ?> Easy isn’t?... » read more