C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Then: The Select method specifies a lambda expression, which applies the string instance method ToUpper to each element in the array.
Uppercase: Each string element is modified to be its uppercase representation. The result of ToUpper is used.
ToLowerFinally: We use the foreach-loop. And the Console.WriteLine method prints the results to the screen.
ForeachConsoleC# program that uses Select method
using System;
using System.Linq;
class Program
{
static void Main()
{
// An input data array.
string[] array = { "cat", "dog", "mouse" };
// Apply a transformation lambda expression to each element.
// ... The Select method changes each element in the result.
var result = array.Select(element => element.ToUpper());
// Display the result.
foreach (string value in result)
{
Console.WriteLine(value);
}
}
}
Output
CAT
DOG
MOUSE
Tip: A lambda expression is the same as a regular method conceptually, but written in a more condensed syntax.
And: This gives you the ability to apply the index to the result of the Select method and its mutation effects.
Overload Method