本文介绍了如何减少列表的数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨我的代码中有一个列表,当我从中删除一个项目时我想减少列表的数量 我尝试了什么: 我测试mylist.count--;我使用了一个变量用于我的工作,但它不是可变的
Hi I have a list in my code and I want to decrease count of the list when I remove an Item from it What I have tried: I test mylist.count--; and I used a variable for my work but it is not sutable
推荐答案你不需要。如果您使用的是标准列表< T>或者(Gawd禁止)甚至是ArrayList,添加或删除项目的行为会自动改变计数。 没有好的情况下,任何人都应该调用方法来删除项目并记住更新项目计数,即使你自己酿造集合 - 删除方法应该始终保持计数正确。 You don't need to. If you are using a standard List<T> or (Gawd forbid) even an ArrayList the act of adding or removing an item alters the count automatically. There is no good case where anyone should have to call a method to remove an item and also remember to update the items count, even if you "brew your own" collection - the remove method should always maintain the count correctly.
更多推荐
如何减少列表的数量
发布评论