我在与WCF项目相同的解决方案中的项目中有一个WPF窗口。在WCF项目中,我有一个包含公共属性和公共方法的公共类。
public class TemporaryExam
{
public Exam Exam { get; set; }
public List<Question> Questions { get; set; }
public List<PossibleAnswer> PossibleAnswers { get; set; }
public void AddQuestion(Question question)
{
Questions.Add(question);
}
public void AddPossibleAnswer(PossibleAnswer possibleAnswer)
{
PossibleAnswers.Add(possibleAnswer);
}
}
在窗口代码隐藏中,我可以为属性赋值,但会收到错误消息,指出TemporaryExam不包含AddQuestion(问题)的定义。
TemporaryExam temporaryExam = new TemporaryExam();
Exam exam = new Exam { Id = Guid.NewGuid(), Title = "Exam3" };
Question question = new Question
{
Id = Guid.NewGuid(),
ExamQuestion = "Vad heter du?",
ExamId_Id = exam.Id
};
PossibleAnswer possibleAnswer = new PossibleAnswer
{
Id = Guid.NewGuid(),
PossibleAnswer1 = "Bamse",
QuestionId_Id = question.Id
};
temporaryExam.AddQuestion(question);
为什么属性可见而不是方法?
修改 这不会产生任何错误:
temporaryExam.Exam = exam;
答案 0 :(得分:0)
尝试从方法中删除类型参数(问题),因为您可能需要定义要从WCF项目公开的自定义类型。