LINQ transforming hierachical data to flat list
You need to look through your code with an analytical eye and discover the pattern that you are implementing. I call it default if (null or) empty.

So I created an extension method to implement that pattern.

public static string DefaultIfEmpty(this string source, string defaultValue)
{
    return string.IsNullOrEmpty(source) ? defaultValue : source;
}


(Note of caution: you may want to choose a different name for it since this method already exists in LINQ; technically, this is an overload, which could create problems if a future version of C# adds this signature.)  

This makes it possible to adapt the LINQ expression:

var currentHead = string.Empty;
var currentValue = string.Empty;
var result = lines.Select(
    line =&gt;
    {
        currentHead = line.Head.DefaultIfEmpty(currentHead);
        currentValue = line.Value.DefaultIfEmpty(currentValue);
        return new { Head = currentHead, Value = currentValue };
    }).ToList();


Sweet, isn't it?