Advertisement
suhendrayputra

Add List to List

Oct 9th, 2018
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.36 KB | None | 0 0
  1. public class ModelResult
  2. {
  3.    public string NAME { get; set; }
  4.    public List<DataPointVM> RESULTs { get; set; }
  5. }
  6.  
  7. public class DataPointVM
  8.     {
  9.         private float v1;
  10.         private float v2;
  11.  
  12.         public DataPointVM(float v1, float v2)
  13.         {
  14.             this.TIME = v1;
  15.             this.VALUE = v2;
  16.         }
  17.  
  18.         public float TIME { get; set; }
  19.         public float VALUE { get; set; }
  20.     }
  21. public class SimulationResult
  22.     {
  23.         public List<ViewModels.ModelResult> mresult { get; set; }
  24.  
  25.         public SimulationResult()
  26.         {
  27.             mresult = new List<ViewModels.ModelResult>(); //create the list
  28.         }
  29.     }
  30.  
  31. List<string> parameterList = new List<string>(new string[] {
  32.    "First",
  33.    "Second",
  34.    "Third"
  35. });
  36.  
  37. int index = 0;
  38. SimulationResult newList = new SimulationResult(); // Final result should store here
  39.            
  40. for (index=0;index<parameterList.Count();index++)
  41. {
  42.    ModelResult mdlres = new ModelResult(); // store temporary list
  43.    List<DataPointVM> points = new List<DataPointVM>(); store details
  44.    
  45.    mdlres.NAME = parameterList[index];
  46.    for (int i = 0; i < 100; i++)
  47.    {
  48.      points.Add(new ViewModels.DataPointVM(TIME<int>, VALUE<float>));
  49.    }
  50.    mdlres.RESULTs = points.ToList(); // store key with details
  51.    newList.mresult.Add(mdlres); create collection of mdlres
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement