Tag: C#

What is the Difference between Readonly and Const in C# ?

If you want to have a field whose value cannot be changed at runtime , you can use either const or readonly keyword . What is the Difference between ReadOnly and Const in C# ? The constant fields must be defined when declaring and cannot be changed at runtime . It is a implicitly static . The read only field can be set when declaring…

How to Use SpeechRecognizer in Windows Phone App using C#?

Below is a sample code snippet demonstrating how to use the SpeechRecognizerUI in your Windows Phone app using C#. Note that by default the speech recognizer API uses the default speech grammar accessed via the Microsoft cloud service and hence requires the network connection to be available for the below code snippet to work. How to Use SpeechRecognizer in Windows Phone App using C#? When…

How to Get the Maximum value from a List of String using LINQ in C# ?

In one of the previous article , we explained how to get the maximum value from a list of integer using LINQ query in C# . What happens when the column is a string instead of integer ?. Below are 2 possibilities on how to get the maximum value from a list of string. How to Get the Maximum value from a List of String…

How to repeat the characters X times in C# ?

You can use the string constructor and pass the character that you wish to be present in it. The string constructor also takes the second parameter to specify the number of times the character to be repeated. How to repeat the characters X times in C# ? Below is a sample code snippet demonstrating how the string constructor can be used to repeat * 4…

How to Convert a List to ObservableCollection in C#?

This simple blog post will explain how to convert a List of Object to ObservableCollection of Object in C# and Windows Phone 8. There are times when you want to convert a List of Object to ObservableCollection specially when binding an ObservableCollection to the LongListSelector etc. The reasons for this can be several. How to Convert a List to ObservableCollection in C#? To Convert a…

How to Rethrow an Exception in C# ?

There are times when you want to handle the exception and then pass it to the higher level . Below is a sample code snippet demonstrating how to Rethrow an exception in C# . How to Rethrow an Exception in C# ?

How to Download Web Content synchronously in C# ?

If you need to download the web content synchronously using C# , you can use the WebClient class that is defined in the System.Net namespace. Below is a sample code snippet demonstrating how to download web content synchronously in c#. How to Download Web Content synchronously in C# ? The output file is generally saved in the same folder where the exe exists.

How to Generate C# class from a XML file ?

Do you want to generate C# class from an XML file ?. You can use the xsd tool to do it. How to Generate C# class from a XML file ? 1. Just launch the Visual Studio Developer Command prompt from the Windows Start menu. 2. Type the command xsd and specify the path of the xml file. xsd d:\test\test.xml 3. This will create the…