Circa interview question

In an array of strings, return the longest string

Interview Answers

Anonymous

8 Jun 2017

Use 2 for loops, index and pointer, loop through array with index, compare with pointer location, return longest string.

Anonymous

17 Feb 2026

quick off the cuff starter solution: using System; public class Program { public static void Main() { Console.WriteLine("The longest string is:"); Console.WriteLine(theLongestString(_stringarray)); } private static string[] _stringarray = new string[]{"fish", "dish", "squish", "a"}; private static string theLongestString (string[] aStringArray) { string current = ""; foreach (string str in aStringArray){ if (current.Length < str.Length) { current = str; } } return current; } }