在.NET中排列一组结构体 [英] Sort an array of structures in .NET
本文介绍了在.NET中排列一组结构体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这只是一个时间,只有蜂巢头脑可以帮助 - 没有数量的Google-fu可以!
我有一个结构数组:
结构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
结束结构
如何在结构的一个变量/属性上排序数组?
Dim car()as stCar = {new stCar(ford,10),new stCar(honda,50)}
cars.sort(MPH)//我该怎么做?
解决方案
假设结构具有名为MPH的属性: / p>
cars = cars.OrderBy(Function(c)c.MPH)
pre>
注意:上面的代码是从以下c#代码自动转换的(如果它包含错误):
cars = cars.OrderBy(c => c.MPH);
This is one of those times when only the hive mind can help - no amount of Google-fu can!
I have an array of structures:
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
How do I sort the array on one variable / property of the structure?
Dim cars() as stCar = {new stCar("ford",10), new stCar("honda",50)} cars.sort("MPH") // how do I do this?
解决方案Assuming that the structure has a property called MPH:
cars = cars.OrderBy(Function(c) c.MPH)
Note: the above code was auto-converted from the following c# code (in case it contains errors):
cars = cars.OrderBy(c => c.MPH);
这篇关于在.NET中排列一组结构体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文