NCF参数化建筑论坛

标题: gh vb.net里的list相关用法 [打印本页]

作者: panhao1    时间: 2010-1-8 16:34
标题: gh vb.net里的list相关用法
本帖最后由 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

作者: panhao1    时间: 2010-1-8 16:38
本帖最后由 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中元素的实际数目
作者: skywoolf    时间: 2010-1-8 16:42
感谢分享,这类的资源太少了.
作者: panhao1    时间: 2010-1-8 16:45
有兴趣的朋友可以交流下写出 求最大,最小值 均值 排序 求和的function 我在群里叫紫暗哦
作者: panhao1    时间: 2010-1-8 17:19
本帖最后由 panhao1 于 2010-1-8 17:22 编辑 3# skywoolf 感谢你的发图方法 这里把list在gh的方法补充完吧 唉~~水印挡住了~~~{:3_55:}
作者: skywoolf    时间: 2010-1-8 18:01
呵呵,这个水印确实是个麻烦,好在勉强能看清~
作者: gzblake    时间: 2010-1-8 21:32
提示: 作者被禁止或删除 内容自动屏蔽
作者: panhao1    时间: 2010-3-24 22:25
稍稍更新了一下 写C#的最好还是不要用arraylist 059版本似乎还缺一些using(程序包) 需要手动导入
作者: wenchongyun    时间: 2010-7-23 16:25
修为不够,看不懂,闪人
作者: seifer0201    时间: 2010-9-10 12:22
收藏了备用,谢谢楼主
作者: archsamxian    时间: 2010-9-10 15:22
收藏备用了~~~~~
作者: richo    时间: 2011-4-13 11:59
哇,最缺的就是这个,多谢多谢
作者: 736415253    时间: 2011-8-30 16:01
收藏了,好东西!
作者: gaojie.cd    时间: 2011-9-12 15:33
请问关于ARRAY的相关函数,另外就是ARRAY和LIST的关系。
作者: carcass    时间: 2011-9-12 16:44
高手了,不懂。。。。。。。。。。。。。。。。。
作者: jsjx200801    时间: 2011-9-13 14:07
路过打怪,积分+1
作者: gaojie.cd    时间: 2011-9-14 10:56
请教各位大虾一个问题,dotnetSDK中在类前面加个I是什么意思,加了I的东西有什么用?另外就是toarray是可以转换任何LIST吗?array和arraylist有什么区别,在GH的VB中哪些时候可以用到,能否举个例子说明下,谢谢。
作者: riddle16_    时间: 2011-9-14 14:04
收藏了备用,谢谢楼主
作者: gaojie.cd    时间: 2011-9-15 09:46
本帖最后由 gaojie.cd 于 2011-9-15 11:51 编辑 4# panhao1 先尝试一下求LIST中最大值的代码吧。 Private Sub RunScript(ByVal x As List(Of Double), ByRef A As Object) 'your code goes here… Dim max As Double = x(0) For i As Integer=0 To (x.count - 1) If x(i) >= max Then max = x(i) Else max = max End If a = max Next End Sub 其实求最小值也是一样思路,改几个符号就行了的。 再来求和和求平均值 Private Sub RunScript(ByVal x As List(Of Integer), ByRef A As Object, ByRef B As Object) 'your code goes here… Dim am As Double = 0 Dim ev As Double For i As Integer=0 To (x.Count - 1) am = am + x(i) ev = am / i Next a = am b = ev End Sub
作者: ping58972    时间: 2011-11-22 20:11
个人认为: List() 这个实现一维数组的类方面 :VB.net 远远不如C#强和安全 可是 在ArrayList() 这个类可以实现多维数组 的确用起来C#不如VB.net好用 因为 在vb可以实现引用多维的概念 而在C# 是不能这样引用 只能一维引用 不管存入什么样的 (这个把我气死了) 可是 用VB编程的代码来写程序 不是很安全的 而C#的代码是目前最流行和最安全的 (所谓的安全的代码就是 等你编程了很多很长的很辛苦 做好的 如果结果是有错误不能执行 这个如果是VB的话就很难找出问题在哪里 而在C#来说就容易一些~~~ )
作者: bizquit    时间: 2011-12-27 17:37
楼主强大啊
作者: 丞丞    时间: 2012-1-30 17:43
谢谢楼主分享。。。。
作者: hacker    时间: 2012-4-28 15:05
感谢分享啊。
作者: hacker    时间: 2012-4-28 15:06
感谢分享啊。
作者: hdhjhz    时间: 2012-4-28 15:07
感谢分享,好帖,好题。
作者: jasonroc    时间: 2014-6-9 12:49
路过,有收获,谢谢~

作者: 冷奴    时间: 2014-8-1 19:26
学习了,谢谢分享
作者: Cbbmaster    时间: 2017-6-15 11:12
panhao1 发表于 2010-1-8 17:19
3# skywoolf
感谢你的发图方法

楼主图片中的这些资料是从哪儿能找到啊




欢迎光临 NCF参数化建筑论坛 (http://bbs.ncf-china.com/) Powered by Discuz! X3.2