I have the following dictionary:
var dict = new Dictionary<string, string> {{"Name", "John"}, {"Age", "28"}};
I want to convert it to a FormField object array as follows:
public class FormField
{
public string FieldName { get; set;}
public string FieldValue { get; set;}
}
I can achieve this by doing the following:
dict.Select(p => new FormField { FieldName = p.Key, FieldValue = p.Value.ToString() }).ToArray()
Now I need to assign this to a view model which has a property as follows:
FormField[] FormData { get; set;}
What is the correct syntax: the following doesnt work?
var viewModel = new MyViewModel
{
FormData = new FormFeild[0] dict.Select(p => new FormField { FieldName = p.Key, FieldValue = p.Value.ToString() }).ToArray()
}
What is the correct syntax to initialise and asign the dictionary to FormData viewmodel which is of type array?