Tag: tutorials
Lock keyword in C#
Want to get the mutual exclusion lock for a given object or a block of statement? If yes, you can use the lock keyword in C# which marks the start of the critical section. The lock keyword may be useful especially when you are using threading in your application. It ensures that only one thread can enter and use the critical section. If another thread…
ElasticSearch – How to Interact with ElasticSearch using JSON over HTTP ?
Problem Statement You need to communicate with ElasticSearch to perform the search or the CRUD operations. Solution You can interact with ElasticSearch using the RESTful API over port 9200. Additionally , ElasticSearch has the official clients for various programming languages like .NET , Java , Ruby etc. The format of the request of ElasticSearch is as specified below. <VERB> <PROTOCOL> ://<HOST>/<PATH>?<QUERYSTRING> Additionally , it can…
Example of Dictionary Initializer in C# 6.0
Below is a sample code snippet demonstrating the usage of Dictionary Initializer syntax in C# 6.0 Example of Dictionary Initializer in C# 6.0
F# Program to display "Hello, World!"
Problem Write a program in F# to display “Hello, World!” on the screen. F# Program to display “Hello, World!” in Console Window. This is a simple F# program that displays “Hello, World!” on the console window. Output Hello, World!
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 add Items to ListBox control in Xaml ?
You can add the Items to a List Box control in Xaml using the Items property . The Items property is an ItemCollection which implements IList. How to add Items to ListBox control in Xaml ? Below is a sample code snippet demonstrating the adding of the Items to ListBox in Xaml of a Windows 10 UWP App. The above showed how to add items…
How to read the complete content of the Text File in C#?
Here’s an easy way to read the complete content of the text file in c# with just one line of code. This is achieved using the System.IO.File.ReadAllText function. Below is a sample code snippet demonstrating how to read the complete content of the Text File in C#? The test1.txt contains the file which needs to be displayed. The test1.txt contains the text “Welcome to Abundantcode.com”….
Java – How to Convert Numbers to Objects and vice versa ?
Problem Statement You need convert numbers to objects and vice versa in your Java program. Solution There are times when you need to pass an object for a function where you have a numeric values. To convert numbers to objects and vice versa , you can use the corresponsing wrapper classes. For example , if you want to convert an int to Integer object or…
C Program to display Inverted half-pyramid using numbers
Problem Write a program in C to print Inverted half-pyramid using numbers as shown below.The program should take the number of rows as input. 1 2 3 4 1 2 3 1 2 1 How to create and display Inverted half-pyramid pattern in C using numbers ? Output Abundantcode.com Coding samples Enter number of rows: 4 1 2 3 4 1 2 3 1 2 …
C++ Program to add two integers
Problem Write a program in C++ to add two integers and display the result on the screen. C++ Program to add two integers Output Enter first number : 8 Enter second number : 2 8 + 2 = 10
Java – How to round floating point number to integer ?
Problem Statement You need to round the floating-point numbers to integers in Java. Solution When you cast a floating value to integer in Java , the value gets truncated. For example , the value 7.8989 when casted to integer will become 7. In order to round he floating-point numbers correctly , you can use the Math.round() method. The Math.round method has a 2 overloaded forms….
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 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#
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…
C# Program to print the sum of two numbers
Problem Write a program in C# to add two numbers and display the result in copnsole window. How to print the sum of two numbers in C# ? Output Abundantcode.com coding sample 35
How to Sort Array Elements in Descending Order in C#?
The Array class includes static method called Sort which can be used to sort the array in ascending order. After using the Sort method, one can use the Reverse method to sort the array back to descending order. How to Sort Array Elements in Descending Order in C#? Below is a sample code snippet demonstrating sorting of array elements in Descending order in C#.
Python Program to display "Hello, World!"
Problem Write a program in Python to display “Hello, World!” on the screen. Python Program to display “Hello, World!” in Console Window. This is a simple Python program that displays “Hello, World!” on the console window. Output Hello, World! The above Python program uses the print() function to display the Hello,World! string to the screen. Note that the strings are enclosed inside the single quotes…
Ruby Program to display "Hello, World!"
Problem Write a program in Ruby to display “Hello, World!”. Ruby Program to display “Hello, World!” This is a simple Ruby program that displays “Hello, World!”. Output
Sending SMS from a Windows Phone 8.1 App
Do you want to send SMS from your Windows Phone 8.1 App ? . You can use the ChatMessage class in Windows Runtime to do it. Sending SMS from a Windows Phone 8.1 App Here’s a code that demonstrates how to send SMS from a Windows Phone 8.1 App .
Java – How to decode string from Hexadecimal and Octal to Integer in Java ?
Problem Statement You need to decode a string from hexadecimal to integer in java as well as octal to integer. Solution Use the decode method defined in the Integer class to decode an hexadecimal and octal number to integer as shown below. The output of the above program is 255 46