Tag: C#

How to Use the Conditional Operator (?) in C# ?

Conditional Operator is also called as ternary operator which lets the developers to select between 2 values with a statement. Assume that you have to check for a number if it is even , we generally tend to use the if else statement . The same can be achieved using the ternary operator in C#. How to Use the Conditional Operator (?) in C# ?…

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

Assign value to enum in c#

You can assign the integer value to enum by casting it to the respective enum type. For example , In the below sample program , you can assign the value 10 to enum by casting the value to the Designation type.

How to Use the Null Coalescing Operator (??) in C# ?

There are times when you simply want to check if the value is null and perform some steps based on the condition . The Null Coalescing Operator (??) can help you achieve this. How to Use the Null Coalescing Operator (??) in C# ? Below is a sample code that uses Null Coalescing Operator (??) in C# to find if the vaklue is null ….

How to get the total number of items in a Enum in C# ?

If you want to get the total number of items that is defined in an enum using C# , you can use the Enum.GetNames static method combined with the Length property. How to get the total number of items in a Enum in C# ? Here’s a code sample demonstrating how to do it. This would display 3 in the console.

How to convert Ascii value to character in C# ?

In C# , you can convert the Ascii value to its corresponding character by assigning the value to a character . How to convert Ascii value to character in C# ? Below is a sample sourcecode to demo how to convert Ascii value to character in C#

Case insensitive string comparison for Contains in C#

When using the string.contains method , the comparison is done based on the exact string that is passed as parameter. In this case , the comparison is case-sensitive. using System; namespace ACConsoleApp { class Program { static void Main(string[] args) { string input = “This is a WeLcome string”; var output = input.Contains(“Welcome”); Console.WriteLine(output); Console.ReadLine(); } } } In the above code snippet , the…

How to Get the List of Appointments from the Calendar App in Windows Phone using C# ?

If you want to programmatically get the list of appointments from the calendar application of your Windows Phone device programmatically , you can use the Microsoft.Phone.UserData.Appointments. How to Get the List of Appointments from the Calender App in Windows Phone using C# ? Enable the ID_CAP_APPOINTMENTS in the WMAppManifest file and then create an instance of the Appointments class and call the SearchAsync method with…

How to Concatenate Strings in C# using LINQ?

Assume that you have an array/List of string which needs to be concatenated. One can concatenate strings using + operator, StringBuilder etc. . . . How about concatenating strings using LINQ? Below is a sample source code that demonstrates how to concatenate strings in C# using LINQ? How to Concatenate Strings in C# using LINQ?

How to Download Web Content asynchronously in C# ?

In one of the previous article , we demonstrated on how to download Web Content asynchronously in C# . This article will demonstrate how to do it asynchronously. How to Download Web Content asynchronously in C# ? The output file is generally saved in the same folder where the exe exists.

C++ Program to display "Hello, World!"

Problem Write a program in C++ to display “Hello, World!” on the screen. C++ Program to display “Hello, World!” in Console Window. This is a simple C++ program that displays “Hello, World!” on the console window. This program provides a quick insight on to the syntax of the C++ language for the beginners. Output Hello, World! The C++ programs starts with the main() function. The…