vb.net打印數(shù)組,c 打印數(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#很相似的

10年積累的網(wǎng)站制作、成都做網(wǎng)站經(jīng)驗(yàn),可以快速應(yīng)對客戶對網(wǎng)站的新想法和需求。提供各種問題對應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識(shí)你,你也不認(rèn)識(shí)我。但先網(wǎng)站策劃后付款的網(wǎng)站建設(shè)流程,更有寧陽免費(fèi)網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。

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ù)組組合情況輸出問題

using System;

using System.Collections.Generic;

using System.Text;

namespace ConsoleApplication42

{

class Program

{

static void Main(string[] args)

{

count = 0;

String[] s = Console.ReadLine().Split(' ');

int[] array = new int[s.Length];

for (int i = 0; i s.Length; i++)

{

array[i] = Convert.ToInt32(s[i]);

}

int m = Convert.ToInt32(Console.ReadLine());

Listint arraylist = new Listint();

arraylist.AddRange(array);

Output(arraylist, m, null);

Console.WriteLine("共有" + count.ToString() + "個(gè)");

Console.ReadKey();

}

static int count = 0;

static void Output(Listint array, int m, Listint output)

{

if (output == null)

output = new Listint();

if (m == 0)

{

for (int i = 0; i output.Count; i++)

{

Console.Write(output[i].ToString() + " ");

}

Console.Write("\r\n");

count++;

return;

}

else

{

for (int i = 0; i array.Count; i++)

{

Listint output2 = new Listint();

output2.AddRange(output.ToArray());

output.Add(array[i]);

Listint array2 = new Listint();

array2.AddRange(array.ToArray());

for (int j = 0; j = i; j++)

{

int number = array[j];

array2.Remove(number);

}

Output(array2, m - 1, output);

output.Clear();

output.AddRange(output2.ToArray());

}

}

}

}

}

額,沒注意VB,用C#寫的。。。

輸出了的,你新建一個(gè)C#控制臺(tái)程序,把這段貼進(jìn)去,運(yùn)行一下就知道了

先輸入一組字符串,然后輸入一個(gè)整數(shù),就會(huì)把所有的組合輸出出來

我把這段轉(zhuǎn)成VB再發(fā)一次吧

Module Module1

Sub Main()

count = 0

Dim s As String() = Console.ReadLine().Split(" ")

Dim array(0 To s.Length - 1) As Integer

For i As Integer = 0 To s.Length - 1

array(i) = Convert.ToInt32(s(i))

Next

Dim m As Integer = Convert.ToInt32(Console.ReadLine())

Dim arraylist As New List(Of Integer)

arraylist.AddRange(array)

Print(arraylist, m, Nothing)

Console.WriteLine("共有" + count.ToString() + "個(gè)")

Console.ReadKey()

End Sub

Sub Print(ByRef array As List(Of Integer), ByVal m As Integer, ByRef output As List(Of Integer))

If output Is Nothing Then

output = New List(Of Integer)()

End If

If m = 0 Then

For i As Integer = 0 To output.Count - 1

Console.Write(output(i).ToString() + " ")

Next

Console.Write(vbCrLf)

count = count + 1

Return

Else

For i As Integer = 0 To array.Count - 1

Dim array2 As New List(Of Integer)

Dim output2 As New List(Of Integer)

output2.AddRange(output.ToArray())

output.Add(array(i))

array2.AddRange(array.ToArray())

For j As Integer = 0 To i

Dim number As Integer = array(j)

array2.Remove(number)

Next

Print(array2, m - 1, output)

output.Clear()

output.AddRange(output2.ToArray())

Next

End If

End Sub

Dim count As Integer = 0

End Module

VB.net 關(guān)于數(shù)組FOR循環(huán)的問題,我是新手求指點(diǎn)

yyyymmdd不是數(shù)組,需要定義成數(shù)組后才能使用

Dim?yyyymmdd(2)?as?String

vb.net 數(shù)組的定義方法

1、點(diǎn)擊VS工具。

2、打開后,新建一個(gè)Windows窗體應(yīng)用程序。

3、新建完畢后,如圖所示。

4、拖動(dòng)一個(gè)按鈕。

5、定義數(shù)組最常見的方法,如圖示。

6、運(yùn)行后,點(diǎn)擊按鈕,彈出提示正常。

7、定義數(shù)組第二種方法,屬于動(dòng)態(tài)的方法。

8、運(yùn)行后,點(diǎn)擊按鈕,數(shù)組成功輸出。

vb.net輸出數(shù)組

1.你說的這個(gè)有點(diǎn)問題,是要只輸出一次,也可做,

2.但問題是如果你數(shù)組還有就看不到了!這個(gè)做法有點(diǎn)問題

1.解決方法:

循環(huán)前面加入一個(gè)變量 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

vb 如何打印數(shù)組元素

假設(shè)你的數(shù)組是a(),且已經(jīng)正確賦值,用以下語句輸出 Dim i As Integer For i = LBound(a) To UBound(a)

Print a(i)

Next

文章題目:vb.net打印數(shù)組,c 打印數(shù)組
當(dāng)前地址:http://muchs.cn/article6/hscpig.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供域名注冊微信小程序、自適應(yīng)網(wǎng)站、網(wǎng)站營銷、網(wǎng)站建設(shè)、靜態(tài)網(wǎng)站

廣告

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

成都網(wǎng)頁設(shè)計(jì)公司