如何通过变量为选项卡赋值c#
How to assing value to tab by variable c#
我正在尝试编写程序来对选项卡进行排序,但无法正常工作 table。这是我的代码:
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();
}
}
}
用户如何从键盘输入制表符的大小?
我不知道该怎么办。我尝试了 return NumberOfObjectInTab
但没有任何变化。使用 void
和 int
选项卡仍然有相同的值。
如果我更改为 static int[] tab = new int[5];
(例如),它会排序但是......我必须有用户定义的选项卡大小,而不是代码。
将您的应用程序分解为执行所需工作所需的功能。也许先从不实施开始。创建实现。
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){...}
How user can enter the size of tab from keyboard?
Console.Write("Enter size of tab:");
var response = Console.ReadLine();
我正在尝试编写程序来对选项卡进行排序,但无法正常工作 table。这是我的代码:
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();
}
}
}
用户如何从键盘输入制表符的大小?
我不知道该怎么办。我尝试了 return NumberOfObjectInTab
但没有任何变化。使用 void
和 int
选项卡仍然有相同的值。
如果我更改为 static int[] tab = new int[5];
(例如),它会排序但是......我必须有用户定义的选项卡大小,而不是代码。
将您的应用程序分解为执行所需工作所需的功能。也许先从不实施开始。创建实现。
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){...}
How user can enter the size of tab from keyboard?
Console.Write("Enter size of tab:");
var response = Console.ReadLine();