table.getn(tableName) 的用法注意。
2010-08-12 17:44
183 查看
转自:http://blog.sina.com.cn/s/blog_4a2e9af90100cv1z.html
1.table.getn(tableName)
--等同于操作符 #
作用:得到一个table的大小。
注意:该table的key必须是有序的,索引是从1开始的。
例如:
a)有序table:
local table1 = {10, 20, 30, 50, 1000};
用table.getn(table1) 或 #table1 得到 5。
b) 无序table:
local table2 = {
["bb"] = 1,
["cc"] = 2,
["dd"] = 3,
["ee"] = nil,
["ff"] = 4,
}
用table.getn(table2) 或 #table2 无法得到正确的大小。
这种table如果想得到大小一般我这样做:
local count = 0
for k,v in pairs(table2) do
count = count + 1
end
1.table.getn(tableName)
--等同于操作符 #
作用:得到一个table的大小。
注意:该table的key必须是有序的,索引是从1开始的。
例如:
a)有序table:
local table1 = {10, 20, 30, 50, 1000};
用table.getn(table1) 或 #table1 得到 5。
b) 无序table:
local table2 = {
["bb"] = 1,
["cc"] = 2,
["dd"] = 3,
["ee"] = nil,
["ff"] = 4,
}
用table.getn(table2) 或 #table2 无法得到正确的大小。
这种table如果想得到大小一般我这样做:
local count = 0
for k,v in pairs(table2) do
count = count + 1
end
相关文章推荐
- Lua table.getn() 用法
- lua中的table.getn()的一些注意事项
- 关于jstl EL用法的注意点(java.lang.NumberFormatException: For input string: "userName")
- 关于jstl EL用法的注意点(java.lang.NumberFormatException: For input string: "userName")
- oracle hint 强制索引 /*+INDEX(TABLE INDEX_NAME)*/ 注意别名
- 关于jstl EL用法的注意点(java.lang.NumberFormatException: For input string: "userName")
- with tableName的用法
- Lua table.getn() 用法
- WITH TABLENAME AS () 类似于临时表用法提高性能
- oracle hint 强制索引 /*+INDEX(TABLE INDEX_NAME)*/ 注意别名
- oracle insert into select * from tablename
- show index from table_name返回列解释
- 数据库性能提高方法1--SET NOCOUNT的用法和注意事项
- SQL2005关于quotename的用法(转)
- 注意this用法,以及当用static 修饰属性时,无论生成多少个对象,其共同拥有一个属性,不再各自拥有自己的属性
- c++中const的用法和注意事项
- solr的copyFeild用法(改变各个feild的权重,修改打分结果)-注意!
- 【我的问题】关于cursor查询的用法的注意事项(Index -1 requested, with a size of 1)
- String.split()用法以及特殊分隔符注意,ps:|
- ssh框架整合的一个教偏的用法<sql-query callable="true" name="myDirInfo">