Files
ASDV-C-Sharp/Student Sample Programs/Chap13/ForEachDemo1/ForEachDemo1/Form1.cs
2022-08-30 14:15:11 -05:00

27 lines
704 B
C#

using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace ForEachDemo1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void demoButton_Click(object sender, EventArgs e)
{
// Create a list of integers.
List<int> numbers = new List<int>() { 1, 2, 3, 4, 5 };
// Create an Action delegate that displays an integer.
Action<int> Display = x => MessageBox.Show(x.ToString());
// Invoke the Display delegate for each element of the List.
numbers.ForEach(Display);
}
}
}