NCF参数化建筑论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 27058|回复: 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:42:55 | 只看该作者
感谢分享,这类的资源太少了.
4m
 楼主| 发表于 2010-1-8 16:45:40 | 只看该作者
有兴趣的朋友可以交流下写出 求最大,最小值 均值 排序 求和的function 我在群里叫紫暗哦
5m
 楼主| 发表于 2010-1-8 17:19:54 | 只看该作者
本帖最后由 panhao1 于 2010-1-8 17:22 编辑 3# skywoolf 感谢你的发图方法 这里把list在gh的方法补充完吧 唉~~水印挡住了~~~{:3_55:}

评分

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

查看全部评分

6m
发表于 2010-1-8 18:01:10 | 只看该作者
呵呵,这个水印确实是个麻烦,好在勉强能看清~
头像被屏蔽
7m
发表于 2010-1-8 21:32:25 | 只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
8m
 楼主| 发表于 2010-3-24 22:25:51 | 只看该作者
稍稍更新了一下 写C#的最好还是不要用arraylist 059版本似乎还缺一些using(程序包) 需要手动导入
9m
发表于 2010-7-23 16:25:48 | 只看该作者
修为不够,看不懂,闪人
10m
发表于 2010-9-10 12:22:48 | 只看该作者
收藏了备用,谢谢楼主
11m
发表于 2010-9-10 15:22:05 | 只看该作者
收藏备用了~~~~~
12m
发表于 2011-4-13 11:59:50 | 只看该作者
哇,最缺的就是这个,多谢多谢
13m
发表于 2011-8-30 16:01:18 | 只看该作者
收藏了,好东西!
14m
发表于 2011-9-12 15:33:24 | 只看该作者
请问关于ARRAY的相关函数,另外就是ARRAY和LIST的关系。
15m
发表于 2011-9-12 16:44:34 | 只看该作者
高手了,不懂。。。。。。。。。。。。。。。。。
16m
发表于 2011-9-13 14:07:44 | 只看该作者
路过打怪,积分+1
17m
发表于 2011-9-14 10:56:30 | 只看该作者
请教各位大虾一个问题,dotnetSDK中在类前面加个I是什么意思,加了I的东西有什么用?另外就是toarray是可以转换任何LIST吗?array和arraylist有什么区别,在GH的VB中哪些时候可以用到,能否举个例子说明下,谢谢。
18m
发表于 2011-9-14 14:04:41 | 只看该作者
收藏了备用,谢谢楼主
19m
发表于 2011-9-15 09:46:54 | 只看该作者
本帖最后由 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
20m
发表于 2011-11-22 20:11:04 | 只看该作者
个人认为: List() 这个实现一维数组的类方面 :VB.net 远远不如C#强和安全 可是 在ArrayList() 这个类可以实现多维数组 的确用起来C#不如VB.net好用 因为 在vb可以实现引用多维的概念 而在C# 是不能这样引用 只能一维引用 不管存入什么样的 (这个把我气死了) 可是 用VB编程的代码来写程序 不是很安全的 而C#的代码是目前最流行和最安全的 (所谓的安全的代码就是 等你编程了很多很长的很辛苦 做好的 如果结果是有错误不能执行 这个如果是VB的话就很难找出问题在哪里 而在C#来说就容易一些~~~ )

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

GMT+8, 2024-4-27 06:59 , Processed in 0.069451 second(s), 22 queries , Gzip On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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