I have the following:
public static class LocalFileModelList
{
public static List<LocalFileModel> ModelList = new List<LocalFileModel>();
}
public class LocalFileModel
{
public string Name { get; set; }
public string Extension { get; set; }
}
Then a method to read all files from a directory.
public static List<LocalFileModel> GetAllFiles(string path)
{
var files = Directory.GetFiles(path, "*.*");
foreach(var file in files)
{
var Extension = Path.GetExtension(file);
var Filename = Path.GetFileNameWithoutExtension(file);
var model = new LocalFileModel
{
Name = Filename,
Extension = Extension,
};
LocalFileModelList.ModelList.Add(model);
}
return LocalFileModelList.ModelList;
}
I noticed that, as I step through my code, when I create a new instance of LocalFileModel, populate it with data then add it to the list. Automatically the list created three additional instances of type null. Once those three were populated with their respective objects, it would again create thre more null instances...

I just realized this now, this is normal?