C#中IEnumerable的问题
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Da...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public class Banks : IEnumerable
{
string[] StrArray = { "中国银行", "工商银行", "农业银行", "建设银行" };
public IEnumerator GetEnumerator()
{
for (int i = 0; i < StrArray.Length; i++)
{
yield return StrArray[i];
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
Banks banks = new Banks();
foreach (string str in banks)
{
richTextBox1.Text += str + "\n";
}
}
}
}
这样在编译时出错,错误为:
错误 1 使用泛型 类型“System.Collections.Generic.IEnumerable<T>”需要 1 个类型参数 ,这是怎么回事,我这个是书上的例程。求解!!! 展开
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public class Banks : IEnumerable
{
string[] StrArray = { "中国银行", "工商银行", "农业银行", "建设银行" };
public IEnumerator GetEnumerator()
{
for (int i = 0; i < StrArray.Length; i++)
{
yield return StrArray[i];
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
Banks banks = new Banks();
foreach (string str in banks)
{
richTextBox1.Text += str + "\n";
}
}
}
}
这样在编译时出错,错误为:
错误 1 使用泛型 类型“System.Collections.Generic.IEnumerable<T>”需要 1 个类型参数 ,这是怎么回事,我这个是书上的例程。求解!!! 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询