我将如何创建一个子过程来按升序对数字进行排序?- VB 控制台 [英] How would I create a sub-procedure to sort numbers in ascending order? - VB console

查看:33
本文介绍了我将如何创建一个子过程来按升序对数字进行排序?- VB 控制台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果有人能帮我解决我的问题,那就太好了.

It would be great if someone could help me out with my problem.

我需要创建一个 VB 控制台应用程序,该应用程序使用子过程将 3 个整数值按升序排序.子过程(例如称为 sortnumber())需要接受 3 个整数参数,然后按升序对值进行排序.

I need to create a VB console application that sorts 3 integer values into ascending order using a sub-procedure. The sub-procedure (e.g. called sortnumber()) needs to accept 3 integer parameters and then sort the values in ascending order.

我将如何做这件事,有人能指出我正确的方向,找到一个代码尽可能简单的解决方案.

How would I go about doing this, could someone point me in the right direction to a solution with code as simple as possible.

谢谢.

模块 Module1

Sub Main()
    Dim num1, num2, num3 As Integer
    Console.WriteLine("Enter first number:")
    num1 = Console.ReadLine
    Console.WriteLine("Enter second number:")
    num2 = Console.ReadLine
    Console.WriteLine("Enter third number:")
    num3 = Console.ReadLine
sortnumber()
End Sub
Sub sortnumber(ByVal num1 As Integer, ByVal num2 As Integer, ByVal num3 As Integer)
    Dim
End Sub

我不知道这是否正确,也不知道我要去哪里..

I have no idea if this is right or where I am going with this..

推荐答案

Module Module1

Public Sub sortnumber(ByVal n1 As Integer, ByVal n2 As Integer, ByVal n3 As Integer)

    Dim l As List(Of Integer) = New List(Of Integer)
    l.Add(n1)
    l.Add(n2)
    l.Add(n3)
    l.Sort()
    For Each h In l
        Console.WriteLine(h.ToString)
    Next

End Sub
Sub Main()
    Dim num1, num2, num3 As Integer
    Console.WriteLine("Enter first number:")
    num1 = Console.ReadLine
    Console.WriteLine("Enter second number:")
    num2 = Console.ReadLine
    Console.WriteLine("Enter third number:")
    num3 = Console.ReadLine
    Console.WriteLine("Calculating ......")
    sortnumber(num1, num2, num3)
    MsgBox("done")

End Sub

End Module

这篇关于我将如何创建一个子过程来按升序对数字进行排序?- VB 控制台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆