简体   繁体   中英

How can I get this base = { base: 'base', prop: '2093482938' } array in JavaScript to C#?

base = { base: 'base', prop: '897070980989'}; ingr_mapArray.push(base); protien = { protein: 'protein', prop: '452341342453'}; ingr_mapArray.puh(protein);

I want to get ingr_mapArray in C# . And wants to store in a List<'Ingrediants> . How can I get this array?

This is how you should go about it

class Ingrediants
{
    string Type { get; set; }
    string Prop { get; set; }
}

Then where you need the list you do

List<Ingrediants> ingr_mapArray = new List<Ingrediants>();

Ingrediants base = new Ingrediants
{
   Type = "base",
   Prop = "897070980989"
};

ingr_mapArray.Add(base);

Ingrediants protien = new Ingrediants
{
   Type = "protien",
   Prop = "452341342453"
};

ingr_mapArray.Add(protien);

In your example, the base object has a property "base" , and similarly protien has "protien" which is not something you can do in the same class. So I named it Type where you can provide either base or protien .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM