C#: how to get the length of string in string[]
<p>I have a collection of string in C#. My Code looks like this:</p>

<pre><code>string[] lines = System.IO.File.ReadAllLines(@"d:\SampleFile.txt");
</code></pre>

<p>What i want to do is to find the max length of string in that collection and store it in variable. Currently, i code this manually, like?</p>

<pre><code>int nMaxLengthOfString = 0;
for (int i = 0; i &lt; lines.Length;i++ )
{               
   if (lines[i].Length&gt;nMaxLengthOfString)
   {
      nMaxLengthOfString = lines[i].Length;
   }
}
</code></pre>

<p>The code above does the work for me, but i am looking for some built in function in order to maintain efficiency, because there will thousand of line in myfile :(</p>
