Tag: C#

How to Call Other Constructors within the Same Class in C# ?

There are times when you want to avoid duplicating code and want to reuse them when working on multiple constructors . If you want to call other constructors from a constructor within the same class , you need to use the this keyword . How to Call Other Constructors within the Same Class in C# ? Below is a sample code snippet that demonstrates how…

Verbatim String Literals in C#

C# supports Verbatim String literals which begin with @ followed by the string data and doesn’t have a escape sequences within the string. This might be specially useful when you want to represent the file path . Below is a representation of Verbatim String Literals in C#

How to provide a default value for Auto Implemented Property in C#?

Sometimes, one might want to provide a default value for the auto implemented properties. For example, you might want to provide a default text for a string value instead of null. This can be achieved by providing the default value in the constructor for the properties. Below is a sample code snippet demonstrating how to do it. How to provide a default value for Auto Implemented…

How to Split a String on newlines in C#?

Ever wanted to split an input string in to new lines in .NET (c#) that has a new line character? Below is a sample code snippet that demonstrates how to do it. How to Split a String on newlines in C#?

Example of Predicate Delegate in C#

Predicate Delegate is an interesting feature in .NET Framework which is like a reference to a function which returns either true or false. Example of Predicate Delegate in C# Below is a sample code snippet demonstrating the usage of Predicate Delegate in C#

How to Download Map in Windows Phone 8 Programatically using C#?

The Windows Phone 8 SDK provides the MapDownloadTask which lets the users to download the region map which can be used for offline usage. This will launch the Map Download App which lets the users to select the map which needs to be downloaded. How to Download Map in Windows Phone 8 Programatically using C#? Below is a sample code snippet demonstrating how the user…

How to Create an Empty array without defining the size in C# ?

When we create an array in C# , we tend to define the size of the array as shown below. Can we create an array without defining the size ? The best option in this  scenario is to use the collection. You can use the Generic List which allows you to add as many items as possible and then you can use the ToArray method…

How to set a property value by reflection in C# ?

There are times when you want to set the property of an object using reflection in C#. Below is a sample code snippet demonstrating how to do it taking the Employee class as an example and Name as the property. How to set a property value by reflection in C# ?

Null Coalescing Operator (??) in C#

The .NET Framework provides the Null Coalescing Operator (??) which is a kind of binary operator and enables the developers to quickly check for the null values . The Null Coalescing Operator (??) in C# can be used with Nullable types as well as reference types . For example , a??b .If a is not null then assign the value a else take the value…

How to Parse a string to Nullable Int in C# ?

Below is a sample code snippet demonstrating how you can convert a string to Nnullable Int in C#. How to Parse a string to Nullable Int in C# ? We use the int.Parse and based on its return value , assign the null or integer value to the Nullable Int.

How to Get the Name of the Anonymous class(type) in C# ?

Below is a sample code snippet which gets the name of the anonymous class . In the below example , the Name and the ID property is set which is anonymous where the type is not specified. When trying to find out the type of the anonymous type , you will get the type as shown in the screenshot below. How to Get the Name…

Alternate Method to Navigate from Page in Windows Phone 8 using C#

The NavigationService.Navigate method i.e. generally used to navigate from one page to another page in Windows Phone 8 SDK. The NavigationService also exposes a property “Source” which can be used to Get/Set the URI of the page . By Setting this property, the Application Frame loads the specified page. Alternate Method to Navigate from Page in Windows Phone 8 using C# Below is a sample…

Top XML Parsers for C++ Developers

Below are the list of some of the top XML parsers for C++ developers. Top XML Parsers for C++ Developers TiCPP It is another name for TinyXML++ and uses some of the powerful C++ features like templates etc. pugixml pugixml is one of the light weight C++ XML processing library which is portable and easy to use and integrate. RapidXML It is one of the…

Important Concepts of Object Oriented Programming in C#

OOPS (Object Oriented Programming) is extensively used in software development to solve many problems. Below are some of the important keywords / concepts of Object Oriented Programming in C# 1. Classes & Objects (Instances) 2. Data Abstraction 3. Encapsulation 4. Inheritance 5. Polymorphism 6. Message Passing etc.

Display the Command line parameters of the Main Method in C#

The Main Method in C# accepts the parameters of string Array. You could easily display the list of parameters of the Main Method in C# by using a for/foreach loop and display the parameters like the example show below using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication4 {     class Program     {         static void Main(string[] args)         {             foreach (string…

Example of Object Initializer in C#

Object Initializer is one of the cool features in C# that lets the developers to initialize the objects as and when they are declared . Example of Object Initialize in C# Below is a sample code snippet that demonstrates how to use Object Initializers in C#.

How to Terminate an Windows Phone 8 App using C#?

If you want to programmatically terminate the windows phone 8 application , you can use the Application.Terminate() method . How to Terminate an Windows Phone 8 App using C#? When using the Application.Terminate() , the developers should make sure that all the necessary data is saved because , the Application Closing event handler wont be raised in this case.