重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
你直接传一个数组进去,而且是一个结构体数组,array.sort怎么知道根据结构中的哪一个属性进行排序?放一个c#的代码你看看,VB和C#很相似的
孟州网站建设公司成都创新互联,孟州网站设计制作,有大型网站制作公司丰富经验。已为孟州成百上千家提供企业网站建设服务。企业网站搭建\外贸网站建设要多少钱,请找那个售后服务好的孟州做网站的公司定做!
class Program
{
static void Main(string[] args)
{
People[] p = new People[3]
{
new People{name="张三"},
new People{name="李四"},
new People{name="张二名"}
};
//重点传一个实现了IComparer接口的类进去,告诉Array.Sort怎么排序
Array.Sort(p, new PeopleCompare());
foreach (var item in p)
{
Console.WriteLine(item.name);
}
Console.ReadKey();
}
}
//People结构体,换成类一样的
public struct People
{
public string name { get; set; }
}
//实现了IComparer接口的类
public class PeopleCompare : IComparer
{
public int Compare(object x, object y)
{
People p1 = (People)x ;
People p2 = (People)y;
return p1.name.CompareTo(p2.name);
}
}
1.你说的这个有点问题,是要只输出一次,也可做,
2.但问题是如果你数组还有就看不到了!这个做法有点问题
1.解决方法:
循环前面加入一个变量 dim Temp as Double=0
For i = 0 To 9
If score(i) avg and score(i)temp Then
TextBox3.Text = TextBox3.Text score(i) " "
if score(i)=avg then
temp=score(i)
end if
End If
Next
先在: My Project 中引用 Microsoft Excel 11.0 Object Library(这个是Excel 2003,Excel 2007 是12.0),之后在窗体代码中加入相关内容就行了。以下是一个窗体的简单实例
假设在C盘根文件夹中有:TEST.xls
Public Class 引用EXCEL窗体
Private A() As String = {"A", "B", "CC", "C", "D"}
Private B() As Integer = {1, 22, 34, 50, 16, 99, 14}
Private excelapp As New Microsoft.Office.Interop.Excel.Application
Private excelworkbook As Microsoft.Office.Interop.Excel.Workbook
Private Sub 引用EXCEL_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim Index As Integer
excelworkbook = excelapp.Workbooks.Open("c:\test.xls")
excelapp.Application.Workbooks.Add(True)
excelapp.Cells(1, 1) = "数组:A"
For Index = 0 To UBound(A)
excelapp.Cells(Index + 2, 1) = A(Index)
Next
excelapp.Cells(1, 2) = "数组:B"
For Index = 0 To UBound(B)
excelapp.Cells(Index + 2, 2) = B(Index)
Next
excelapp.Visible = True
End Sub
End Class
运行结果:
数组:A 数组:B
A 1
B 22
CC 34
C 50
D 16
99
14