C#检查指定对象是否存在于ArrayList集合中的方法
作者:令狐不聪 时间:2023-07-28 00:45:17
本文实例讲述了C#检查指定对象是否存在于ArrayList集合中的方法。分享给大家供大家参考。具体分析如下:
C#的ArrayList提供了一个专用的Contains方法来检测ArrayList是否包含指定的对象,返回值是一个bool类型
ArrayList alcollect = new ArrayList();
// Add individual items to the collection
string str = "learn csharp";
alcollect.Add(str);
//check existence of object
if(alcollect.Contains(str))
{
Console.WriteLine(alcollect.IndexOf(str));
}
else
{
Console.WriteLine("Not found!");
}
希望本文所述对大家的C#程序设计有所帮助。
标签:C#,检查,集合,对象
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
基于Java代码操作Redis过程详解
2022-03-28 06:53:58
![](https://img.aspxhome.com/file/2023/9/113259_0s.jpg)
C#利用异或算法实现加密解密
2022-08-15 14:48:51
![](https://img.aspxhome.com/file/2023/0/116460_0s.png)
Java实现的求解经典罗马数字和阿拉伯数字相互转换问题示例
2023-10-15 23:17:36
![](https://img.aspxhome.com/file/2023/9/64789_0s.png)
Android自定义覆盖层控件 悬浮窗控件
2021-10-21 01:14:40
如何动态替换Spring容器中的Bean
2023-05-22 20:18:59
C++中关键字Struct和Class的区别
2022-12-23 11:25:06
Android开发笔记之:一分钟学会使用Logcat调试程序的详解
2022-07-19 05:17:22
![](https://img.aspxhome.com/file/2023/8/139408_0s.png)
C# TrackBar拖动条改变滑块颜色
2021-12-22 22:11:07
![](https://img.aspxhome.com/file/2023/5/122695_0s.gif)
springboot+log4j.yml配置日志文件的方法
2023-08-07 11:33:17
![](https://img.aspxhome.com/file/2023/5/67955_0s.png)
Spring Boot 启动加载数据 CommandLineRunner的使用
2021-06-17 12:52:21
Android如何从实现到封装一个MVP详解
2023-02-12 10:44:40
![](https://img.aspxhome.com/file/2023/5/138775_0s.png)
面试官:java ThreadLocal真的会造成内存泄露吗
2023-11-18 13:04:56
![](https://img.aspxhome.com/file/2023/7/79937_0s.png)
Winform中Treeview实现按需加载的方法
2023-08-01 11:45:32
JVM垃圾收集器详解
2022-10-06 10:46:00
![](https://img.aspxhome.com/file/2023/8/78938_0s.png)
利用spring aop实现动态代理
2022-02-02 16:50:25
![](https://img.aspxhome.com/file/2023/1/122971_0s.jpg)
C#日期格式字符串的相互转换操作实例分析
2021-09-01 10:06:56
Java数据结构之实现哈希表的分离链接法
2023-09-06 04:50:17
![](https://img.aspxhome.com/file/2023/0/78930_0s.png)
C# Winform实现波浪滚动效果
2023-05-05 04:36:54
![](https://img.aspxhome.com/file/2023/8/92838_0s.jpg)
如何解决SpringBoot集成百度UEditor图片上传后直接访问404
2022-03-03 19:27:13
![](https://img.aspxhome.com/file/2023/5/128235_0s.png)
C#操作PowerPoint的方法
2023-03-17 03:48:16