unity之迭代器
来源:互联网 发布:淘宝卖大米属于哪类 编辑:程序博客网 时间:2024/06/07 17:04
喜欢我的博客请记住我的名字:Candy,我的博客的地址是:http://unity.gopedu.com/home.php?mod=spacecp&ac=blog,欢迎来到我们的狗刨网
学习。今天我们讲的是迭代器。
一、迭代器的概念:
迭代器是一种对象,它能够用来遍历STL容器中的部分或全部元素,每个迭代器对象代表容器中的确定的地址。迭代器修改了常规指针的接口,所谓迭代器是一种概念上的抽象:那些行为上象迭代器的东西都可以叫做迭代器。然而迭代器有很多不同的能力,它可以把抽象容器和通用算法有机的统一起来。
二、迭代器的语法:
IEnumerator<表名>it =list.GetEnumerator();
那下面就拿个例子来说吧:
IEnumerator<Users> it = list.GetEnumerator();
while (it.MoveNext())
{
Console.WriteLine(it.Current.Name);
}
三、接下来是我们讲的项目的细节,其实最重要的还是数据的增删改查,这是贯穿项目的核心。
public int InsertUsers(string name, string password, string sex)
{
SqlConnection con = new SqlConnection("server=.;database=GameMarket;Trusted_Connection=SSPI");
con.Open();
string sql = "insert into users values('" + name + "','" + password + "','" + sex + "')";
SqlCommand sc = new SqlCommand(sql, con);
int i = sc.ExecuteNonQuery();
return i;
}
*这是增删改的一个类型,只要把这个掌握了,其它的就都可以顺手拿来,因为改变的只有数据库的语句。
public List<Equipment> SelectEquipment()
{
List<Equipment> list = new List<Equipment>();
SqlConnection con = new SqlConnection("server=.;database=GameMarket;Trusted_Connection=SSPI");
con.Open();
string sql = "Select *from equipment";
SqlCommand sc = new SqlCommand(sql, con);
SqlDataReader sd = sc.ExecuteReader();
while (sd.Read())
{
Equipment eq = new Equipment();
eq.Id = (int)sd.GetValue(0);
eq.Name = (string)sd.GetValue(1);
eq.Number = (int)sd.GetValue(2);
eq.Price = (int)sd.GetValue(3);
eq.Powers = (string)sd.GetValue(4);
list.Add(eq);
}
return list;
}
这是数据库的查,这是比较复杂的内容,但在项目中也是很重要的。
欢迎来到我们的狗刨网,我们每天都会更新新的内容,欢迎来到我们的狗刨网观看。
0 0
- unity之迭代器
- Unity之Unity基本操作
- unity之入门经验
- unity菜鸟之路
- unity之Animation组件
- Unity之局域网通信
- Unity之渲染问题
- Unity开发之Android
- unity学习之公路
- Unity学习之三
- unity之小结
- unity之数组
- unity之枚举
- unity之抽象类
- unity之接口
- unity之接口
- unity之数据库
- unity之集合
- 基于TCP协议的Socket
- 考试系统--底层框架发布时遇到的问题解决方案(Window7 IIS6.0)(一)
- 无废话WCF入门教程二[WCF应用的通信过程]
- 日志14-12-15
- redhat添加交换空间
- unity之迭代器
- Posix信号量基本知识
- 数据库设计 一对多,多对多
- 基于SOUI开源项目开发的一个 资源搜索器,大家来吐槽吧。
- jquery 筛选元素方法
- 让Eclipse代码自动完成!
- 简单工厂模式见编程艺术
- 穷举法解决组合问题
- HOJ 11109 Traversal of binary tree(前、中序遍历求后序遍历)