c# - Assign values to inner class object -
i have class below
public class hintquestion { public string questioncode { get; set; } public string questionname { get; set; } } and calss below
public class user { public user() { hintquestion = new hintquestion(); } public hintquestion hintquestion { get; set; } } the problem when create instance of user calss , assign values inner class object not working. using object initialize
user u=new user{hintquestion.questioncode ="",... but when created constructors it's working fine.
public class hintquestion { public string questioncode { get; set; } public string questionname { get; set; } } public class user { public user() { this.hintquestion = new hintquestion(); } public hintquestion hintquestion { get; set; } } user u = new user { hintquestion = new hintquestion { questioncode = "test", questionname = "test1" } };
c# oop
No comments:
Post a Comment