当前位置:网站首页>Array sort 1
Array sort 1
2022-07-26 04:29:00 【VB.Net】
Copyright notice : This article is an original blog article , For reprint, please indicate the source of this article and the author's network name in a prominent position , May not be used for commercial purposes without the permission of the author .
About the sorting of arrays , The easiest way is to call Array.Sort() Method . This method will use Array Of each element in IComparable Realization , For the whole one dimension Array The elements in are sorted .
Refer to the following code :
Sub Main()
Dim testarr() As Integer = New Integer() {12, 44, 2, 54, 1, 24, 77, 12, 33}
Dim copyarr1() As Integer
copyarr1 = testarr.Clone
Array.Sort(copyarr1)
Console.WriteLine(" Sorted array :")
For i As Integer = 0 To copyarr1.Length - 1
Console.Write(copyarr1(i) & " ")
Next
Console.WriteLine()
Console.WriteLine(" Original array :")
For i As Integer = 0 To testarr.Length - 1
Console.Write(testarr(i) & " ")
Next
Console.WriteLine()
Console.ReadKey()
End SubThe operation results are as follows :

What about the order from big to small ? Use Array.Reverse() The method is ok , The code is as follows :
Sub Main()
Dim testarr() As Integer = New Integer() {12, 44, 2, 54, 1, 24, 77, 12, 33}
Dim copyarr1() As Integer
copyarr1 = testarr.Clone
Array.Sort(copyarr1)
Console.WriteLine(" Sorted array :")
For i As Integer = 0 To copyarr1.Length - 1
Console.Write(copyarr1(i) & " ")
Next
Console.WriteLine()
Dim copyarr2() As Integer
copyarr2 = testarr.Clone
Array.Sort(copyarr2)
Array.Reverse(copyarr2)
Console.WriteLine(" Sort arrays from large to small :")
For i As Integer = 0 To copyarr2.Length - 1
Console.Write(copyarr2(i) & " ")
Next
Console.WriteLine()
Console.WriteLine(" Original array :")
For i As Integer = 0 To testarr.Length - 1
Console.Write(testarr(i) & " ")
Next
Console.WriteLine()
Console.ReadKey()
End SubThe operation results are as follows :

because .net Under the platform C# and vb.NET Very similar , This article can also be C# Provide reference for enthusiasts .
Learn more vb.net knowledge , Please see vb.net course Catalog
边栏推荐
- Weights & Biases (二)
- What if win11 cannot wake up from sleep? Solution of win11 unable to wake up during sleep
- 香甜的黄油
- FFmpeg 视频编码
- 低成本、快速、高效搭建数字藏品APP、H5系统,扇贝科技专业开发更放心!
- 2、 Internationally renowned project HelloWorld
- Under the high debt of Red Star Macalline, is it eyeing new energy?
- idea插件离线安装(持续更新)
- Life related -- the heartfelt words of a graduate tutor of Huake (mainly applicable to science and Engineering)
- egg-ts-sequelize-CLI
猜你喜欢
Yuansaka Lin wallpaper

数组排序3

UE4 靠近物体时显示文字,远离时文字消失

Sangi diagram of machine learning (for user behavior analysis)

MATLAB绘图

Design and implementation of smart campus applet based on cloud development

7、 Restful

UE4 通过按键控制物体的旋转

数组排序1

Tutorial on using the one click upgrade function of the rtsp/onvif protocol video platform easynvr service
随机推荐
Steam science education endows classroom teaching with creativity
解析Steam教育的课程设计测评体系
Acwing_12. 背包问题求具体方案_dp
Recommendation Book Educational Psychology: a book for tomorrow's teachers~
MySQL only checks the reasons for the slow execution of one line statements
dijikstra(先预处理)+dfs,relocation truncated to fit
性能和成本的综合架构:单元化架构
SEGGER Embedded Studio找不到xxx.c或者xxx.h文件
Recognized again | saining network security has been listed in the ccsip 2022 panorama of China's network security industry
Day26 job
qt编译报错整理及Remote模块下载
Page pull-up refresh and pull-down loading
Which websites can I visit to check the latest medical literature?
二、国际知名项目-HelloWorld
Graph translation model
1. If function of Excel
香甜的黄油
支持代理直连Oracle数据库,JumpServer堡垒机v2.24.0发布
Design and implementation of smart campus applet based on cloud development
Rotate array minimum number