using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ForeachDemo { class Program { static void Main() { Mylist list = new Mylist(); MyList2 list2 = new…
以前对于foreach的使用都是自然而然的感觉,没有深究过为什么可以用,什么时候可以用.最近才发现,原来那些可以使用的类,都是实现了Iterable接口的,否则根本就不能用. 下面是我之前学习时候写的代码 package com.test.basic; import java.util.Iterator; public class MyMap implements Iterable<Integer>{ private int count; public MyMap(int i) { this.…