我正在建立一些簡單的東西,但已經有一個錯誤。如何在運行代碼後使用某個名稱來描述新數組?
總結:當我的代碼運行用戶將寫一些句子到cmd,我的代碼將它分離成單詞。 到目前爲止,這是沒問題的。分離後,我想使陣列的每個字 例如:
cmd screen =" hello world "
seperating to words = hello , world
making them arrays (program should do these aoutomatically)
string[] hello = new string[5]
和
string[] world = new string[5]
這是問題的開始。我想在運行後命名這些新陣列。你會寫「蘋果」CMD和新名稱「蘋果」陣列應彈出。已經向我的老師詢問這個問題,他說可以用動態貴重物品(var等)來完成。但我不知道如何。在這裏我的代碼到目前爲止:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;
using System.Text.RegularExpressions;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
List<string> tümkelimeler = new List<string>();
for (int i = 1; i < 100; i++)
{
tümkelimeler.Insert(i, "null");
}
int ü = 0;
while (ü == 0)
{
string s = Console.ReadLine();
string[] kelimeler = s.Split(' ');
// this is where i seperate words from sentence .
}
Console.ReadKey() ;
}
}
}
#Complete Code
就這麼你知道,你幾乎不想這樣做。永遠。 *特別*當你剛剛學習時。這種代碼反映了糟糕的設計/實踐。 – BradleyDotNET