我必须为Question.cs
:
namespace Project.Classes.DataTypes
{
public class Question_SubType
{
public int TotalNoOfAnswer { get; set; }
public int TotalNoOfViews { get; set; }
public string Category { get; set; }
public string PostedDateTime { get; set; }
public string UserName { get; set; }
public string QuestionText { get; set; }
public string Subject { get; set; }
public int QuestionId { get; set; }
}
public class Question
{
public Question_SubType question { get; set; }
public string Email { get; set; }
public bool AskAsAnonymous { get; set; }
}
}
在我的MainPage.xaml.cs
中,我的代码会给我错误:
Question q1 = new Question();
q1.Email = "hello@hello.com"; //Works Fine
q1.question.QuestionId = 10; //Gives Error
q1.question.Subject = "this is my question subject?"; //Gives Error
虽然我看到AskAsAnonymous
为null
,Email
为null
,但question
也为null
。所以它给了我错误:
类型' System.NullReferenceException'的例外情况发生在Project.exe中但未在用户代码中处理
我需要在Question.cs
或MainPage.xaml.cs
进行哪些更改?