public static void Main()
string[] s = {"flower", "flow", "flight"};
Console.WriteLine(longestCommonPrefix(s));
public static string longestCommonPrefix(string[] s) {
string commonPrefix = s[0];
while(length < s[0].Length)
string pref = commonPrefix.Substring(0,length);
foreach(string word in s)
if(word.Length>=length && word.Substring(0,length).Equals(pref))
return s[0].Substring(0, length-1);
return s[0].Substring(0, length);