GetEnumerator方法
来源:互联网 发布:阿里云栖大会 ppt 编辑:程序博客网 时间:2024/05/19 12:24
任何集合类对象都有一个GetEnumerator()方法,该方法可以返回一个实现了 IEnumerator接口的对象,这个返回的IEnumerator对象既不是集合类对象,也不是集合的元素类对象,它是一个独立的类对象。通过这个对象,可以遍历访问集合类对象中的每一个元素对象 .
例说明如何使用 GetEnumerator 方法创建一个实现了 System.Collections.IEnumerator 接口的对象。然后循环访问该对象以显示选定行中的项。
view plaincopy to clipboardprint?
<%@ Page Language="C#" AutoEventWireup="True" %>
<HTML>
<HEAD>
<SCRIPT runat="server">
void Page_Load(Object sender, EventArgs e)
{
int numrows = 5;
int numcells = 6;
int counter = 1;
ArrayList a_row = new ArrayList();
// Create a table.
for (int j=0; j<numrows; j++)
{
TableRow r = new TableRow();
for (int i=0; i<numcells; i++)
{
TableCell c = new TableCell();
c.Text=counter.ToString();
r.Cells.Add(c);
counter++;
}
Table1.Rows.Add(r);
}
if (!IsPostBack)
{
// Create a DropDownList for the number of rows.
for (int k=0; k<numrows; k++)
{
a_row.Add(k.ToString());
}
List1.DataSource=a_row;
List1.DataBind();
}
}
void Button_Click(object sender, EventArgs e)
{
int row = List1.SelectedIndex;
TableCell current_cell;
// Create the IEnumerator.
IEnumerator myEnum = Table1.Rows[row].Cells.GetEnumerator();
Label1.Text = "The items in the selected row are: ";
// Iterate through the IEnumerator and display its contents.
while (myEnum.MoveNext())
{
current_cell = (TableCell)myEnum.Current;
Label1.Text = Label1.Text + " " + current_cell.Text;
}
}
</SCRIPT>
<H3>TableCellCollection Example</H3>
<FORM runat="server">
<ASP:TABLE id=Table1 runat="server" />
<BR><BR>
<CENTER>
Select a row:
<BR><BR>
Row:
<ASP:DROPDOWNLIST id=List1 runat="server" />
<BR><BR>
<ASP:BUTTON id=Button1 on
<BR><BR>
<ASP:LABEL id=Label1 runat="server" />
</CENTER>
</FORM>
- GetEnumerator 方法
- GetEnumerator方法
- GetEnumerator
- C# 集合类对象 GetEnumerator()方法
- Linq and GetEnumerator
- luacom GetEnumerator 不好使?
- C# GetEnumerator用法
- GetEnumerator系列用法
- IEnumerable与IEnumerator学习(一):在类中添加GetEnumerator()方法使类或类的集合可以被迭代
- IEnumerable、GetEnumerator、IEnumerator之间的关系
- IEnumerable、GetEnumerator、IEnumerator之间的区别
- 求解:System.IEquatable<T>”不包含“GetEnumerator”的公共定义,因此 foreach 语句不能作用于“System.IEquatable<T>”类型的变量
- “System.Data.DataSet”不包含“GetEnumerator”的公共定义,因此 foreach 语句不能作用于“System.Data.DataSet”类型的变量
- 方法
- 方法
- 方法
- 方法
- 方法
- 与微软CRM相比,方程软件的个性化优势
- ASP 中利用OWC 服务器端组件动态生成图表
- window 下 zendframework 安装
- 操作系统基础知识
- 在众多CRM软件中,方程软件CRM好在哪里
- GetEnumerator方法
- ASP.NET+GridView实现行链接
- 在程序运行中调整UITableViewCell高度
- C语言 打造最快的Hash表
- 用一句话地道你的口语!
- C++的强制类型转换
- 分享8个优秀的WordPress缓存插件
- UML类图关系
- 编写Android触摸屏手势识别