C# Corner

C# Corner

  • Tech Writer
  • 7
  • 435

How do I create a list of values in C# ?

Dec 15 2018 6:35 AM
How to create a list of values in C# based on the following data?

I have the following which I need to be converted into list:
  1. Players: [  
  2.     {  
  3.       Player: {  
  4.         PlayerType: Advanced,  
  5.         PlayerRole: 12  
  6.       }  
  7.     }  
  8.   ]  


and I did this

  1. public class Players  
  2.         {  
  3.             public Players()  
  4.             {  
  5.                 Player = new PlayerMemo();  
  6.             }  
  7.             [JsonProperty("Player")]  
  8.             public Player Player { getset; }  
  9.   
  10.         }  
  11.   
  12.         public class Player  
  13.         {  
  14.   
  15.             public string PlayerRole { getset; }  
  16.   
  17.             public string PlayerType { getset; }  
  18.   
  19.         } 


I need to convert this into one line list and add it to the previously declared
localvariable.list = here-goes-my-one-line-list: (something like this)

  1. loadgroup.Players = new Players()  
  2.             {  
  3.                 { new Players() {"PlayerRole""Member"} },  
  4.               
  5.             }; 

Answers (3)