if (books[i].IndexOf(s) != -1)未处理NullReferenceException怎么办!
using System;using System.Collections.Generic;
using System.Text;
namespace BooksEnqiries
{
class Program
{
static void Main(string[] args)
{
string[] books = new string[5];
int[] n = new int[5];
int i, j;
string s;
books[0] = "Vicual C# 程序设计案例教程";
books[0] = "Vicual Basic 程序设计案例教程";
books[0] = "Vicual 程序设计案例教程";
books[0] = "Vicual C++ 程序设计案例教程";
books[0] = " 案例教程";
Console.WriteLine(" 图书查询\n");
Console.Write("输入要查询的内容:");
s = Console.ReadLine();
j = 0;
for (i = 0; i < books.Length; i++)
{
//利用string类的IndexOf方法来查询图书名称中是否有与输入的s相符的
//如果没有,则返回-1;如果有,则返回相符字符的起始位置索引
if (books[i].IndexOf(s) != -1)
{
n[j] = i;
j++;
}
}
if (j > 0)
{
Console.Write("与{0} 相关的图书有:", s);
for (i = 0; i < j; i++)
{
Console.Write("{0} ", books[n[i]]);
}
}
else
{
Console.WriteLine("没有符合条件的图书!");
}
Console.ReadLine();
}
}
}