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
.