NCF参数化建筑论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 27552|回复: 27
打印 上一主题 下一主题

[VB & C#] gh vb.net里的list相关用法

[复制链接]
跳转到指定楼层
1m
发表于 2010-1-8 16:34:33 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 panhao1 于 2010-1-26 17:07 编辑 来源为ms官网 自己整理了一下 不知道怎么调字体 55555~~ 定义
Dim instance As New List()
——————————————————————————
Dim capacity As Integer
Dim instance As New List(capacity)
——————————————————————————————
Dim collection As IEnumerable(Of T)
Dim instance As New List(collection)
Eg: Dim dinosaurs As New List(Of String) —————————————————————————— Dim dinosaurs As New List(Of String)(4) A List(Of (T)) of strings with a capacity of 4 is created ———————————————————————————————————————— Dim input() As String = { "Brachiosaurus", "Amargasaurus","Mamenchisaurus" } Dim dinosaurs As New List(Of String)(input) The collection whose elements are copied to the new list. 成员 1 List(Of (T)).Capacity
Dim instance As List
Dim value As Integer
value = instance.Capacity
instance.Capacity = value
2 List(Of (T)). Count
Dim instance As List
Dim value As Integer
value = instance.Count
Capacity is the number of elements that the List (Of (T)) can store before resizing is required. Count is the number of elements that are actually in the List(Of (T)). 3List(Of (T)).Item
Dim instance As List
Dim index As Integer
Dim value As T
value = instance.Item(index)
instance.Item(index) = value
Gets or sets the element at the specified index
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏2 分享分享
2m
 楼主| 发表于 2010-1-8 16:38:33 | 显示全部楼层
本帖最后由 panhao1 于 2010-3-24 15:25 编辑 常用方法 1添加一个元素 Dim instance As List Dim item As T instance.Add(item) 2添加一个集合 Dim instance As List Dim collection As IEnumerable(Of T) instance.AddRange(collection) 3清除
Dim instance As List
instance.Clear() 4 查找元素位置
Dim instance As List
Dim item As T
Dim returnValue As Integer
returnValue = instance.IndexOf(item) 5插入元素
Dim instance As List
Dim index As Integer
Dim item As T
instance.Insert(index, item)
————说明: If Count already equals Capacity, the capacity of the List(Of (T)) is increased by automatically reallocating the internal array, and the existing elements are copied to the new array before the new element is added. If index is equal to Count, item is added to the end of List(Of (T)).
———— 6 插入集合
Dim instance As List
Dim index As Integer
Dim collection As IEnumerable(Of T)
instance.InsertRange(index, collection) 7 移除
Dim instance As List
Dim item As T
Dim returnValue As Boolean
returnValue = instance.Remove(item) 8反转(还有特殊反转)
Dim instance As List
instance.Reverse() 9转成array
Dim instance As List
Dim returnValue As T()
returnValue = instance.ToArray() 更新一下帖子· List的方法和属性 方法或属性 作用 Capacity 用于获取或设置List可容纳元素的数量。当数量超过容量时,这个值会自动增长。您可以设置这个值以减少容量,也可以调用trin()方法来减少容量以适合实际的元素数目。 Count 属性,用于获取数组中当前元素数量 Item( ) 通过指定索引获取或设置元素。对于List类来说,它是一个索引器。 Add( ) 在List中添加一个对象的公有方法 AddRange( ) 公有方法,在List尾部添加实现了ICollection接口的多个元素 BinarySearch( ) 重载的公有方法,用于在排序的List内使用二分查找来定位指定元素. Clear( ) 在List内移除所有元素 Contains( ) 测试一个元素是否在List内 CopyTo( ) 重载的公有方法,把一个List拷贝到一维数组内 Exists( ) 测试一个元素是否在List内 Find( ) 查找并返回List内的出现的第一个匹配元素 FindAll( ) 查找并返回List内的所有匹配元素 GetEnumerator( ) 重载的公有方法,返回一个用于迭代List的枚举器 Getrange( ) 拷贝指定范围的元素到新的List内 IndexOf( ) 重载的公有方法,查找并返回每一个匹配元素的索引 Insert( ) 在List内插入一个元素 InsertRange( ) 在List内插入一组元素 LastIndexOf( ) 重载的公有方法,,查找并返回最后一个匹配元素的索引 Remove( ) 移除与指定元素匹配的第一个元素 RemoveAt( ) 移除指定索引的元素 RemoveRange( ) 移除指定范围的元素 Reverse( ) 反转List内元素的顺序 Sort( ) 对List内的元素进行排序 ToArray( ) 把List内的元素拷贝到一个新的数组内 trimToSize( ) 将容量设置为List中元素的实际数目

评分

参与人数 1强度 +5 照度 +50 收起 理由
skywoolf + 5 + 50 精品资源

查看全部评分

3m
 楼主| 发表于 2010-1-8 16:45:40 | 显示全部楼层
有兴趣的朋友可以交流下写出 求最大,最小值 均值 排序 求和的function 我在群里叫紫暗哦
4m
 楼主| 发表于 2010-1-8 17:19:54 | 显示全部楼层
本帖最后由 panhao1 于 2010-1-8 17:22 编辑 3# skywoolf 感谢你的发图方法 这里把list在gh的方法补充完吧 唉~~水印挡住了~~~{:3_55:}

评分

参与人数 1强度 +3 照度 +30 收起 理由
skywoolf + 3 + 30

查看全部评分

5m
 楼主| 发表于 2010-3-24 22:25:51 | 显示全部楼层
稍稍更新了一下 写C#的最好还是不要用arraylist 059版本似乎还缺一些using(程序包) 需要手动导入

小黑屋|手机版|NCF参数化建筑论坛 ( 浙ICP备2020044100号-2 )    辽公网安备21021102000973号

GMT+8, 2024-5-8 08:20 , Processed in 0.337085 second(s), 22 queries , Gzip On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表