我收到此錯誤當我嘗試運行時System.Core.dll中發生未處理的類型'System.ArgumentNullException'異常該程序。它給了我諸如「在調用方法之前確定對象爲空」和「使用」新「關鍵字來創建對象實例」的建議「。爲什麼我得到System.Core.dll中發生類型'System.ArgumentNullException'的未處理異常
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
protected static string userString { get; set; }
public virtual void GetUserString()
{
Console.WriteLine("Enter a string of letters: ");
userString = Convert.ToString(Console.ReadLine());
}
class ProgramOrder : Program
{
public virtual void SetOrder()
{
bool moveOn = userString.All(Char.IsLetter); //Error here
base.GetUserString();
if (moveOn == true)
{
char[] array = userString.ToCharArray();
for (int i = array.Length - 1; i >= 0; i--)
{
Console.Write("{0}", array[i]);
}
}
else
{
Console.WriteLine("You used characters that are not letters.");
Console.WriteLine("Please use ONLY letters.");
SetOrder();
}
}
}
class TestProgram
{
static void Main(string[] args)
{
ProgramOrder P1 = new ProgramOrder();
P1.SetOrder();
Console.WriteLine("Press any key to continue...");
Console.ReadLine();
}
}
}
}
你的完整例外包括堆棧跟蹤在哪裏? –