Files
dotNetStudyWithGPT/MySolution/ConsoleApp/Samples/StringLengthSample.cs

40 lines
932 B
C#
Raw Normal View History

2023-05-11 11:47:56 +09:00
using System;
2023-05-11 13:56:53 +09:00
namespace Samples.StringLength
2023-05-11 11:47:56 +09:00
{
2023-05-11 13:56:53 +09:00
class StringLengthSample
2023-05-11 11:47:56 +09:00
{
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);
}
}
}
}