//declare a string as empty
string large = "";
//function to find largest string
public void FindLargest(string[] str)
{
foreach (string s in str)//for each string in string array
{
//compare the length of each string in an array
if (s.Length > large.Length)
{
large = s;
}
}
Console.WriteLine(large);
}
//for input string array as "hi","hello"
Output: hello
No comments:
Post a Comment