I have a DataModel class in my C# program like below.
public class DataModel
{
public string num1 { get; set; }
public string num2 { get; set; }
public string num3 { get; set; }
public string num4 { get; set; }
public string num5 { get; set; }
}
I need to do value assignment as below. The left side num1..num5 are TextBlock. The right side data.num1..data.num5 are initialized in another page already and will assign them to TextBlock's Text property. How to make it by using a for() loop? Thanks!
protected override void OnNavigatedTo(NavigationEventArgs e)
{
if (e.Parameter != null && e.Parameter is DataModel)
{
var data = e.Parameter as DataModel;
string str;
num1TextBlock.Text = data.num1;
num2TextBlock.Text = data.num2;
num3TextBlock.Text = data.num3;
num4TextBlock.Text = data.num4;
num5TextBlock.Text = data.num5;
Sorry for the unclear description. Updated, please check again. Thanks!
More: If the array count is not fixed to 5 (5 is the minimal count), for example, we pull data from our server and after that we know how much data we need to do the assignment(initializing). How to do it?