vb.net數(shù)組sort vb6數(shù)組

VB.net 數(shù)組怎么按任意元素的順序排序輸出

你直接傳一個(gè)數(shù)組進(jìn)去,而且是一個(gè)結(jié)構(gòu)體數(shù)組,array.sort怎么知道根據(jù)結(jié)構(gòu)中的哪一個(gè)屬性進(jìn)行排序?放一個(gè)c#的代碼你看看,VB和C#很相似的

創(chuàng)新互聯(lián)專注網(wǎng)站設(shè)計(jì),以設(shè)計(jì)驅(qū)動(dòng)企業(yè)價(jià)值的持續(xù)增長(zhǎng),網(wǎng)站,看似簡(jiǎn)單卻每一個(gè)企業(yè)都需要——設(shè)計(jì),看似簡(jiǎn)潔卻是每一位設(shè)計(jì)師的心血 十余年來,我們只專注做網(wǎng)站。認(rèn)真對(duì)待每一個(gè)客戶,我們不用口頭的語(yǔ)言來吹擂我們的優(yōu)秀,1000+的成功案例見證著我們的成長(zhǎng)。

class Program

{

static void Main(string[] args)

{

People[] p = new People[3]

{

new People{name="張三"},

new People{name="李四"},

new People{name="張二名"}

};

//重點(diǎn)傳一個(gè)實(shí)現(xiàn)了IComparer接口的類進(jìn)去,告訴Array.Sort怎么排序

Array.Sort(p, new PeopleCompare());

foreach (var item in p)

{

Console.WriteLine(item.name);

}

Console.ReadKey();

}

}

//People結(jié)構(gòu)體,換成類一樣的

public struct People

{

public string name { get; set; }

}

//實(shí)現(xiàn)了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);

}

}

VB.NET數(shù)組的排序法?

如果你是從vb6剛過渡上vb。net,建議還是用冒泡排序法,容易理解。

如果你正努力學(xué)習(xí)vb。net的方法,推薦一個(gè)例子如下:

Imports System

Imports System.Collections

Public Class SamplesArray

Public Class myReverserClass

Implements IComparer

' Calls CaseInsensitiveComparer.Compare with the parameters reversed.

Function Compare(x As Object, y As Object) As Integer _

Implements IComparer.Compare

Return New CaseInsensitiveComparer().Compare(y, x)

End Function 'IComparer.Compare

End Class 'myReverserClass

Public Shared Sub Main()

' Creates and initializes a new Array and a new custom comparer.

Dim myArr As [String]() = {"The", "QUICK", "BROWN", "FOX", "jumps", "over", "the", "lazy", "dog"}

Dim myComparer = New myReverserClass()

' Displays the values of the Array.

Console.WriteLine("The Array initially contains the following values:")

PrintIndexAndValues(myArr)

' Sorts a section of the Array using the default comparer.

Array.Sort(myArr, 1, 3)

Console.WriteLine("After sorting a section of the Array using the default comparer:")

PrintIndexAndValues(myArr)

' Sorts a section of the Array using the reverse case-insensitive comparer.

Array.Sort(myArr, 1, 3, myComparer)

Console.WriteLine("After sorting a section of the Array using the reverse case-insensitive comparer:")

PrintIndexAndValues(myArr)

' Sorts the entire Array using the default comparer.

Array.Sort(myArr)

Console.WriteLine("After sorting the entire Array using the default comparer:")

PrintIndexAndValues(myArr)

' Sorts the entire Array using the reverse case-insensitive comparer.

Array.Sort(myArr, myComparer)

Console.WriteLine("After sorting the entire Array using the reverse case-insensitive comparer:")

PrintIndexAndValues(myArr)

End Sub 'Main

Public Shared Sub PrintIndexAndValues(myArr() As [String])

Dim i As Integer

For i = 0 To myArr.Length - 1

Console.WriteLine(" [{0}] : {1}", i, myArr(i))

Next i

Console.WriteLine()

End Sub 'PrintIndexAndValues

End Class 'SamplesArray

'This code produces the following output.

'

'The Array initially contains the following values:

' [0] : The

' [1] : QUICK

' [2] : BROWN

' [3] : FOX

' [4] : jumps

' [5] : over

' [6] : the

' [7] : lazy

' [8] : dog

'

'After sorting a section of the Array using the default comparer:

' [0] : The

' [1] : BROWN

' [2] : FOX

' [3] : QUICK

' [4] : jumps

' [5] : over

' [6] : the

' [7] : lazy

' [8] : dog

'

'After sorting a section of the Array using the reverse case-insensitive comparer:

' [0] : The

' [1] : QUICK

' [2] : FOX

' [3] : BROWN

' [4] : jumps

' [5] : over

' [6] : the

' [7] : lazy

' [8] : dog

'

'After sorting the entire Array using the default comparer:

' [0] : BROWN

' [1] : dog

' [2] : FOX

' [3] : jumps

' [4] : lazy

' [5] : over

' [6] : QUICK

' [7] : the

' [8] : The

'

'After sorting the entire Array using the reverse case-insensitive comparer:

' [0] : the

' [1] : The

' [2] : QUICK

' [3] : over

' [4] : lazy

' [5] : jumps

' [6] : FOX

' [7] : dog

' [8] : BROWN

vb.net 數(shù)組中的重復(fù)項(xiàng)

我還在床上,就只給你思路吧

我是自己寫了個(gè)函數(shù),將數(shù)組傳入并返回一個(gè)新數(shù)組列表

子函數(shù)中,先將數(shù)組排序sort函數(shù),然后有兩個(gè)循環(huán),外循環(huán)從0到Length,變量i,內(nèi)循環(huán)從i到Length,判斷第i個(gè)數(shù)是否與包括自身的后續(xù)數(shù)相同,相同就有變量加1,內(nèi)循環(huán)結(jié)束條件是找到第一個(gè)不同的數(shù),并將外循環(huán)i復(fù)植為內(nèi)循環(huán)中第一個(gè)不同的數(shù)的下表。。。

這個(gè)是思路,如果不能理解再再追加我給你代碼,不過建議自己試試

你看寫這個(gè),和你的要求差不多。。。;oldq=1

有程序的~~~你可以參考下~~~

新聞標(biāo)題:vb.net數(shù)組sort vb6數(shù)組
URL分享:http://muchs.cn/article42/hjsoec.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營(yíng)銷、定制開發(fā)、外貿(mào)網(wǎng)站建設(shè)、外貿(mào)建站、品牌網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站建設(shè)