.NET Fiddle

CSharp · Console

/Program.cs

using System;
					
public class Program
{
	public static void Main()
	{
		var longestWord = returnLongestWord(new []{ "word1", "word12", "word1234", "mostdefinitelythelongestword!", "aShorterWord", "anotherShortWordThanTheMax"});
		
		Console.WriteLine("\nDone - longest word: " + longestWord);
	}
	
	public static string returnLongestWord(string[] words)
	{
		string maxWord = "";
		int ctr = 0;
		foreach (var word in words)
		{
					
			if (word.Length > ctr)
			{
				maxWord = word;
				ctr = word.Length;
			}
			
			Console.WriteLine("ctr: " + ctr + ", for word:\t " + maxWord);
		}
		return maxWord;
	}
}
;