I have a class like below
public class HintQuestion
{
public string QuestionCode { get; set; }
public string QuestionName { get; set; }
}
and another calss like below
public class User
{
public User()
{
HintQuestion = new HintQuestion();
}
public HintQuestion HintQuestion { get; set; }
}
The problem is when I create an instance of User
calss and assign values to inner class object it is not working. I am using object initialize
User u=new user{HintQuestion.QuestionCode ="",...
But when I created constructors it's working fine.
Using an object initializer you have to set the User.HintQuestion
property the same way as you do in your constructor, assign a HintQuestion
object to it, which you can also create using an initializer:
User u = new User {
HintQuestion = new HintQuestion { QuestionCode = "", QuestionName = "" }
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With