Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Access an object properties from a string variable

$
0
0

Dear Developers,

I am looking for a way to access an object from a string value.

I have a class describing the object Card that contains properties related to the Card points :
public class Card
 {
public int Health { get; set; }

public int Magic { get; set; }
}

myCard = new Card();
myCard.Health = 5;
myCard.Magic = 3;

Then, based on a card name store in a variable (choice =  "myCard"), I want to access the card properties : choice.Health.

The thing is that the object « choice » doesn’t exist because the targeted object should be « myCard ».

Any idea how I could do that ?

Thank you very much


Viewing all articles
Browse latest Browse all 204402

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>