當我運行它給我這個錯誤代碼:如何在使用兩個單獨的類時解決NullReferenceException?
An exception of type 'System.NullReferenceException' occurred in App.dll but was not handled in user code
Additional information: Object reference not set to an instance of an object.
我將如何解決這個問題?
ExceptionHandling ExManager = new ExceptionHandling();
var Message = ExManager.ExceptionLibrary["10000"]// occured here
類ExceptionHandling
public class ExceptionHandling
{
private Dictionary<string, string> exceptionlibrary;
public Dictionary<string, string> ExceptionLibrary
{
get { return exceptionlibrary; }
set
{
exceptionlibrary = new Dictionary<string, string>()
{
//User
{"10000", "Invalid user input."},
{"10001", "Phone number is already registered."},
};
}
}
}