C# ExceptBy() extension method.

The following extension method is used to compare values from two list and it returns entities from the first list which is not present in the second list based on the key that is passed to it. public static IEnumerable<T> ExceptBy<T, TKey>(this...

Reading from a file hosted on a server using C#

This post describes how to read a file which is hosted on server i.e on some url. Let’s say I have a .txt file hosted here – www.yassershaikh.com/salary.txt I want my code to read from this hosted file. Below is how you do it using WebClient class. var...

Convert a List of items to an XElement in C#

I have always used XElement.Parse() and StringBuilder to create an XElement of a required type. Today I came across this post on some blog and then this thread on stackoverflow which show how to do the same in a more efficient manner. Sharing it here hope this helps....

Serialize a List of Object to JSON in C#

This can be easily be done using Json.NET. Json.NET is a popular high-performance JSON framework for .NET. First of all, you will need to download the latest binary from here and include it your project. using Newtonsoft.Json; Rest of the code is pretty self...