You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
913 B
40 lines
913 B
using System;
|
|
|
|
namespace Samples
|
|
{
|
|
class StringLength
|
|
{
|
|
public static void Sample()
|
|
{
|
|
string[] words = new string[]
|
|
{
|
|
"Apple",
|
|
"Banana",
|
|
"Cherry",
|
|
"Pear",
|
|
};
|
|
|
|
CalculateStringLength(words, PrintStingLength);
|
|
}
|
|
|
|
private static void CalculateStringLength(string[] words, Action<int[]> callback)
|
|
{
|
|
int[] lengths = new int[words.Length];
|
|
for (int i = 0; i < words.Length; i++)
|
|
{
|
|
lengths[i] = words[i].Length;
|
|
}
|
|
|
|
if (callback != null)
|
|
callback(lengths);
|
|
}
|
|
|
|
private static void PrintStingLength(int[] lengths)
|
|
{
|
|
foreach (int length in lengths)
|
|
{
|
|
Console.WriteLine(length);
|
|
}
|
|
}
|
|
}
|
|
} |