Initializing the model with multiple arrays.
I have already tried to initialize but its not working.
namespace ArrayTest.Models
{
public class Question
{
public string question { get; set; }
public string[] option { get; set; }
public string[] score { get; set; }
}
}
public class DefaultController : Controller
{
public ActionResult Index()
{
IEnumerable<Question> x = new List<Question>
{
new Question(){ question = "Question1", option = { "abc","cde","efg"}, score = { "abc", "cde", "efg" } },
new Question(){},
new Question(){},
new Question(){}
};
return View(x);
}
}
I expect this model to be initialized and sent to the view.
new Question(){question="Question1", option= new string[3] { "abc","cde","efg"},score=new string[3]{ "abc", "cde", "efg" }as you are trying to initialize anarray. So, inC#your have to define the type along with the size.List<T>would be better? You are tight coupling then ratherIEnumerable<T>would be better suggestion