如何通过变量c#为tab赋值

时间:2017-11-07 22:20:28

标签: c# sorting user-interface tabs tab-size

我试图让程序对标签进行排序,但我无法制作工作台。这是我的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SorotwanieTablic
{
    class Program
    {
        static int NumberOfObjectInTab;

        static void Numb(int NumberOfObjectInTab)
        {
            do
            {
                Console.WriteLine("Wprowadź  liczbę  elementów do posortowania <1 .. 10>: ");

                Program.NumberOfObjectInTab = int.Parse(Console.ReadLine());
            }
            while (NumberOfObjectInTab < 0 || NumberOfObjectInTab > 10);

        }

static int[] tab = new int[NumberOfObjectInTab];

        static void InsertValuesToTab(int[] tab)

        {
           for (int i=0; i < tab.Length; i++)
            {
                Console.WriteLine("Wprowadź  liczbę  [{0}] ", i);
                tab[i] = int.Parse(Console.ReadLine());
            }           
        }




        static void Main(string[] args)
        {
            Numb(NumberOfObjectInTab);
            InsertValuesToTab(tab);
            Console.WriteLine("\nprzed sortowaniem ");
            foreach (int i in tab) Console.Write(+i + " ");
            Array.Sort(tab);
            Console.WriteLine("\nPO Posortowaniu ");
            foreach (int i in tab) Console.Write( + i + " ");


            Console.Read();

        }
    }
}

用户如何从键盘输入标签大小? 我不知道该怎么办。我试过返回NumberOfObjectInTab但没有任何改变。使用voidint时,标签的值仍然相同。 如果我更改为static int[] tab = new int[5];(例如),则排序...但我必须具有用户定义的标签大小,而不是代码。

1 个答案:

答案 0 :(得分:0)

将您的应用程序分解为执行所需工作所需的功能。也许首先从非实施开始。创建实现。

 static int sizeOfTab;
 static int[] tab;



static void Main(string[] args)
{
        CollectSizeOfTab(args);

        CreateTab();

        InsertValuesToTab(tab);

        Sort(tab);

}

static void CollectSizeOfTab(string[] args)
{
    do
    {
      Console.WriteLine("Wprowadź  liczbę  elementów do posortowania <1 .. 10>: ");

      sizeOfTab = int.Parse(Console.ReadLine());
    }while (sizeOfTab < 0 || sizeOfTab > 10);
}

static void CreateTab(){tab = new int[sizeOfTab];}
static void InsertValuesToTab(int[] tab){...}
static void Sort(int[] tab){...}
  

用户如何从键盘输入标签大小?

Console.Write("Enter size of tab:");
var response = Console.ReadLine();
相关问题