Tag: C#

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

The Windows Phone 8 SDK provides the MapUpdaterTask which lets the users to update the region map downloaded earlier which can be used for offline usage. This will launch the Map Settings App which lets the users about the updates to the map (if available). How to Update Map in Windows Phone 8 Programatically using C#? Below is a sample code snippet demonstrating how the…

How to Get the Battery Level from a Windows Phone 8 device using C#?

The Windows Phone 8 SDK provides the Windows.Phone.Devices.Power.Battery class which can be used to retrieve the battery information of the windows phone. Use the Windows.Phone.Devices.Power.Battery.GetDefault ().RemainingChargePercent property to retrieve the Battery Level from a Windows Phone 8 device programatically using C#. How to Get the Battery Level from a Windows Phone 8 device using C#? Below is a sample code snippet demonstrating the steps used…

How to find if the character entered is Digit in C# ?

The Char class provides a method Char.IsDigit that lets you find if the character entered in the specid string is a digit or not. How to find if the character entered is Digit in C# ? Below is a sample code demonstrating the Char.IsDigit to find if the character entered is Digit in C#.

Use of var keyword in C#

The var keyword in C# was introduced from C# 3.0 and it beings in the feature of local type inference or implicit type variable in C#. LINQ is one of the case where var keyword can be widely used in C#. Eg: In the above example, the initialization of the name was done using “string” and hence name will be implicitly treated as string. Note…

How to Create an Interface in C# ?

You might need to few functionalities without defining any implementation of the abstract methods. This should later be applied to various types within your project. In this case , one can create an interface which specifies some behavior rather than what the type or member is all about. How to Create an Interface in C# ? Below is a sample interface called IMusic The interface…

Convert.ChangeType Method in C#

The .NET Framework has the Convert.ChangeType Method which converts the object specified to the conversion type. The value should implement the IConvertible interface for the conversion to be successful. Convert.ChangeType Method in C# Below is a simple code snippet demonstrating Convert.ChangeType Method in C#

How to Throw an Exception in C# ?

To indicate and error which can be handled by the caller function , you can use the throw keyword to throw an exception . For example , below is a sample code snippet demonstrating how to throw an exception in C#. How to Throw an Exception in C# ?

How to check if the number is positive or negative in C# ?

You can use the > and < operator to check if the number is a positive or negative number in C#. How to check if the number is positive or negative in C# ? If the number is less than zero , it can be considered as negative number. If the number is greater than zero , it is a positive number. Below is a…

How to detect if a key exists in a Dictionary in C# ?

If you want to detect if a key exists in a dictionary in C# , you can use the contains method of the dictionary which return true if the key is found. How to detect if a key exists in a Dictionary in C# ? Below is a sample source code that illustrates how to find out if the exists in a dictionary using the…

How to Create a Guid Value in C# ?

If you want to create a new Guid value in C# which is random , you can use the Guid class to achieve it. Below is a sample code snippet demonstrating how to do it. How to Create a Guid Value in C# ?

How to get last four characters from a string in C#?

This post will provide a simple tip showing how you can get the last 4 characters from a string in C#. How to get last four characters from a string in C#? Assume that you have a string that contains the value “CodersEditor.com” and you wish to get .com from the string and display it. Below is a sample code snippet demonstrating how you can…