加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

vb.net – 在.NET中对结构数组进行排序

发布时间:2020-12-17 00:08:54 所属栏目:大数据 来源:网络整理
导读:这是只有蜂巢头脑可以提供帮助的时代之一 – 没有多少Google-fu可以! 我有一系列结构: Structure stCar Dim Name As String Dim MPH As Integer Sub New(ByVal _Name As String,ByVal _MPH As Integer) Name = _Name MPH = _MPH End SubEnd Structure 如何
这是只有蜂巢头脑可以提供帮助的时代之一 – 没有多少Google-fu可以!

我有一系列结构:

Structure stCar 
    Dim Name As String
    Dim MPH As Integer

    Sub New(ByVal _Name As String,ByVal _MPH As Integer)
        Name = _Name
        MPH = _MPH
    End Sub
End Structure

如何在结构的一个变量/属性上对数组进行排序?

Dim cars() as stCar = {new stCar("ford",10),new stCar("honda",50)}

cars.sort("MPH") // how do I do this?
假设该结构具有称为MPH的属性:
cars = cars.OrderBy(Function(c) c.MPH)

注意:上面的代码是从以下c#代码中自动转换的(如果它包含错误):

cars = cars.OrderBy(c => c.MPH);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读