程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程解疑 >> c#-C#交叉數組出現未將對象引用設置到對象的實例 問題

c#-C#交叉數組出現未將對象引用設置到對象的實例 問題

編輯:編程解疑
C#交叉數組出現未將對象引用設置到對象的實例 問題

代碼其實很簡單,創建一個C#窗體應用程序,運行時輸入“媽媽和小女孩在動物園看熊貓”,但總是報錯,卻又解決不了。求解

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

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string[][] data = new string[25][];

        data[0] = new string[] { "媽媽", "麻麻", "老媽", "老麻", "母親", "娘", "老娘", "阿姨", "女士", "女人", "姐姐", "嬸嬸", "女朋友", "老婆", "女性", "她" };

        data[1] = new string[] { "書房", "房間", "工作室", "家裡", "工作間" };

        data[3] = new string[] { "工作", "學習", "看書" };

        data[4] = new string[] { "電話", "手機" };

        data[4] = new string[] { "書架", "書櫃", "書櫥", "書桌" };

        data[5] = new string[] { "翻閱", "查閱", "閱覽", "查找", "查詢", "查找", "查", "閱讀" };

        data[6] = new string[] { "開燈", "照亮", "光明" };

        data[7] = new string[] { "水族館", "海底世界", "大海", "水裡", "水下", "水中", "海中", "深海" };

        data[8] = new string[] { "鯨", "鯨魚" };

        data[9] = new string[] { "鲨", "鲨魚", "大白鲨" };

        data[10] = new string[] { "水母" };

        data[11] = new string[] { "動物園", "動物世界" };

        data[12] = new string[] { "小女孩", "女孩", "女子", "女紙", "女生", "女森", "女兒", "妹妹" };

        data[13] = new string[] { "熊貓", "大熊貓" };

        data[14] = new string[] { "竹", "竹子" };

        data[15] = new string[] { "草", "草原", "草叢" };

        data[16] = new string[] { "馬", "馬匹", };

        data[17] = new string[] { "魚", "魚群" };

        data[18] = new string[] { "珊瑚", "珊瑚海", "珊瑚礁" };

        data[19] = new string[] { "章魚", "烏賊" };

        data[20] = new string[] { "鼠標" };

        data[21] = new string[] { "台燈", "燈" };

        data[22] = new string[] { "熊" };

        data[23] = new string[] { "虎" };

        data[24] = new string[] { "獅子" };

         string[] resource;
        resource = new string[25];

        resource[0] = "x-010100";
        resource[1] = " x-010200";
        resource[2] = " x-010300";
        resource[3] = " x-010400";
        resource[4] = " x-010500";
        resource[5] = " x-010600";
        resource[6] = " x-010700";
        resource[7] = " x-010800";
        resource[8] = " x-010900";
        resource[9] = " x-020100";
        resource[10] = " x-020200";
        resource[11] = " x-020300";
        resource[12] = " x-020400";
        resource[13] = " x-020500";
        resource[14] = " x-020600";
        resource[15] = " x-020700";
        resource[16] = " x-030100";
        resource[17] = " x-030200";
        resource[18] = " x-030300";
        resource[19] = " x-030400";
        resource[20] = " x-030500";
        resource[21] = " x-030600";
        resource[22] = " x-030700";
        resource[23] = " x-040100";
        resource[24] = " x-040200";





        string information;
        information = Console.ReadLine();        //獲取查詢的字符串
        string statics;
        for (int i = 0; i < data.Length; i++)
        {
            for (int j = 0; j < data[i].Length; j++)
            {
                Regex reg = new Regex(data[i][j]);
                if (reg.IsMatch(information))
                {

                    statics = resource[i] + " ";
                    Console.WriteLine("你要的代碼串為{0}", statics);

                }
            }
        }
        Console.ReadKey();
    }

}

}




最佳回答:


data[1] = new string[] { "書房", "房間", "工作室", "家裡", "工作間" };
data[3] = new string[] { "工作", "學習", "看書" };
明顯data[2]沒有賦值,你循環的時候就null了

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved