Lua 計算表中有多少個元素 table的用法

2021-06-08 18:52:56 字數 441 閱讀 3665

通常情況下,檢視table表中有多少個元素,我們習慣用#table,但是當table的元素裡有key值的時候,比如 table = ,這種情況下,需要輸出table表中的元素個數的時候,如果直接使用「#table」就會出錯。

錯誤例子:

所以在這種情況下,可以用for迴圈來做輸出。

下面是例子:(函式 counttb(tbdata) 能計算出表tbdata的元素數目)

總是有各種各樣的小問題,都是常識來的~可能犯錯了以後會驚覺~這麼2的錯誤也會犯~真是的……

嗯~這次記住了~下次不要犯啦~o(∩_∩)o~

多少個元素

多少個元素 time limit 2000msmemory limit 131072kb64bit io format lld llu submit status practice hpu 1401 description 給定q次操作 每次操作給定乙個正整數x 表示向集合a和集合b裡面各加入乙個元...

sql server 查詢資料庫中有多少個表

select from sysobjects where xtype u select from sysobjects where xtype u select from sysobjects where xtype c select from sysobjects where xtype d se...

sql server 查詢資料庫中有多少個表

select from sysobjects where xtype u select from sysobjects where xtype u select from sysobjects where xtype c select from sysobjects where xtype d se...