My xml:
<Configuration>
<LaunchDebugger>false</LaunchDebugger>
<RequestFolder>./Request</RequestFolder>
<ResponseFolder>./Response</ResponseFolder>
<Countries>
<Country NumericCode="1FH" FileName="file1.xml">1</Country>
<Country NumericCode="20H" FileName="file2.xml">2</Country>
<Country NumericCode="" FileName="file3.xml">3</Country>
</Countries>
</Configuration>
Country class:
public class Country
{
public String Name { get; set; }
public String NumericCode { get; set; }
public String FileName { get; set; }
}
This is how i create objects from it using LINQ:
CountryList = (from filter in Configuration.Descendants("Countries").Descendants("Country")
select new Country()
{
Name = (string)filter.Value,
NumericCode = (string)filter.Attribute("NumericCode"),
FileName = (string)filter.Attribute("FileName")
}).ToList();
Parsing xml works, i get all 3 countries in my list, but i also get one extra null object as the last item of the list.

Any idea why that would be happening?
Reason is simple –
List<T>has default capacity equal to 4. Capacity gets or sets the total number of elements the internal data structure can hold without resizing. Internal data structure is a simple arrayprivate Country[] _items, which is initially has length equal to 4. Thus there is reserved place for forth element, which is null until element assigned. But don’t worry – elements count will be3if you check.Here is an image, which shows both public (three items) and internal data structure (array of capacity size)