Checking string length limitation and add items to it in a shorter way with Linq This method has three parameters. If the extension is not null, for each item in list try to add extension to main text in a way that length of result doesn't exceed 20.

I wrote this code, but I don't like its style. I like to use Linq and newer styles for doing this, in order to make it shorter.

public string AddExtension(IList&lt;string&gt; extension, bool needDefaultAdd, string text )
{
    if (needDefaultAdd)
    {
        if (extension==null)
        {
            string tempText = text + "deafult extension txt";
            if (text.Length &gt;20)
            {
                return text;
            }
            else
            {
                return tempText;
            }
        }
        else
        {
             string finalResult = null;
            foreach (var e in extension)
            {

                string tempText = text + "deafult extension txt";
                if (text.Length &gt; 20)
                {
                    finalResult=text;
                }

                var temp2Text = tempText +e;
                if (text.Length &gt; 20)
                {
                    finalResult=tempText;
                }
                else
                {
                    finalResult = finalResult + temp2Text;
                }
            }
            return finalResult;
        }

    }
    return text;
}
Reduce nesting by putting a negated condition first:

if (! needDefaultAdd)
{
    return text;
}