如何减少列表的数量

编程入门 行业动态 更新时间:2024-10-06 16:17:24
本文介绍了如何减少列表的数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

嗨我的代码中有一个列表,当我从中删除一个项目时我想减少列表的数量 我尝试了什么: 我测试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.

更多推荐

如何减少列表的数量

本文发布于:2023-11-30 15:28:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1650511.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数量   列表

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!