using Microsoft.VisualStudio.TestTools.UnitTesting; using System; using System.Collections.Generic; [TestClass] public class ListTest { [TestMethod] public void TestGetEnumerator() { Listnumbers = new List () { 1, 2, 3, 4, 5 }; IEnumerator enumerator = numbers.GetEnumerator(); while (enumerator.MoveNext()) { int number = enumerator.Current; Console.WriteLine(number); } } }
using Microsoft.VisualStudio.TestTools.UnitTesting; using System.Collections.Generic; [TestClass] public class ListTest { [TestMethod] public void TestGetEnumerator() { ListIn this example, we create a `List` object of integers and use the `GetEnumerator()` method to obtain an enumerator. We then iterate over the elements of the list and find the sum of its elements. Finally, we use the `Assert` class to check that the sum is equal to the expected value of 15.numbers = new List () { 1, 2, 3, 4, 5 }; IEnumerator enumerator = numbers.GetEnumerator(); int sum = 0; while (enumerator.MoveNext()) { int number = enumerator.Current; sum += number; } Assert.AreEqual(15, sum); } }