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了

解决方案二:

楼上已解,初学者,凡事需谨慎

时间: 2025-01-01 10:13:52

c#-C#交叉数组出现未将对象引用设置到对象的实例 问题的相关文章

C#传递数组对象报错“未将对象引用设置到对象的实例”

问题描述 publicvoidHISBloodSendInfo(refstringerrorMessage,StructHelper.sendBloodInfogSendBloodInfo,StructHelper.sendBloodListInfo[]gSendBloodListInfo){errorMessage="";try{HisService.HisServiceSoapClientTMISClient=newHisService.HisServiceSoapClient()

c#中创建Mat类数组,出现未将对象引用设置到对象的实例

问题描述 本身并不是很懂c#,但是老师的要求,没法拒绝,只能硬着头皮上,问题如下:开发环境是vs2010+emgucv,创建了一个Mat类,但是总出现未将对象引用设置到对象的实例,各位大神,求救啊~~~~~代码片段如下:Mat[]img=null;privatevoidbutton2_Click(objectsender,EventArgse){if(img1!=null){//img2=newMat(img1.Rows,img1.Cols,Emgu.CV.CvEnum.DepthType.Cv

winform 未将对象引用设置到对象的实例。

问题描述 winform 未将对象引用设置到对象的实例. 这可能是什么原因导致的,搞了半天都没弄懂 解决方案 你在sel()方法中SQL参数 upl.PATIENT_ID 没有值 解决方案二: 最近写程序,被这个错误折磨完了,今天总结一下,看看是不是这些!未将对象引用设置到对象的实例(1)一般都是控件名称与codebehind里面的没有对应(2)很多初学者都会有疑问:我已经定义了变量 public string[] c,而且也进行了实例化 string[] c=new string[3],但是为

解决:getWeatherbyCityName(city),服务器无法处理请求。 ---&gt; 未将对象引用设置到对象的实例。

原文:getWeatherbyCityName(city),服务器无法处理请求. ---> 未将对象引用设置到对象的实例. 解决方法:不要直接使用 "服务引用" , 添加为 "Web 引用"        最近用C#在winform中做一个天气预报的小程序,在网上搜了很多资料,包括现成的程序,如http://blog.csdn.net/qishuangquan/article/details/6039287,但运行到getWeatherbyCityName(c

未将对象引用设置到对象的实例。

问题描述 Pointtemp=newPoint();for(intk=0;k<picbox.Width/5-1;k++){temp=ptlist[k+1];ptlist[k]=newPoint(temp.X-5,temp.Y);}出线错误:未将对象引用设置到对象的实例.是怎么回事儿? 解决方案 解决方案二:if(ptlist==null)就别执行了解决方案三:先检查ptlist是否为null,在执行解决方案四:引用1楼net_lover的回复: if(ptlist==null)就别执行了 改了之

ASP.NET未将对象引用设置到对象的实例(C#)

问题描述 usingSystem;usingSystem.Data;usingSystem.Data.OleDb;usingSystem.Configuration;usingSystem.Collections;usingSystem.Web;usingSystem.Web.Security;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Web.UI.WebControls.WebParts;usingSystem.

vb.net在用多线程时,提示“未将对象引用设置到对象的实例”

问题描述 代码如下:PublicClassForm1DimPath(,)AsInteger,fun(,)AsSingle,q0(,),v0AsSingleDimz(,)AsSingle,v(,)AsSinglePrivateSubForm1_Load(senderAsObject,eAsEventArgs)HandlesMyBase.LoadFori=1ToUBound(Q)Forj=1Tonz(i,j)=zmax-(zmax-zmin)/(n-1)*(j-1)Call插值图(mmg,gz,gv

VB.NET提示未将对象引用设置到对象的实例

问题描述 VB.NET提示未将对象引用设置到对象的实例 我做毕业设计,用VB.NET设计界面,打开pre/e的模型,但是一直错误,求指点 Imports pfcls Imports System.Reflection.Assembly Public Class 建模 Public asyncConnection As IpfcAsyncConnection Public cac As CCpfcAsyncConnection Dim model As IpfcModel Public param

错误解决:System.NullReferenceException: 未将对象引用设置到对象的实例

在ASP.NET开发中,遇到System.NullReferenceException: 未将对象引用设置到对象的实例的错误提示,解决方法如下:       (1)所设置的变量为空值或没有取到值,一般出现在传递参数的时候出现这个问题,也会在使用datagrid或gridview或datalist等数据控件时出现. (2)控件名称与codebehind里面的没有对应 (3)未用new初始化对象 (4)在程序中所引用的控件不存在 解决方法: (1)使用try..catch...finally捕捉错误