public static List<CardData> cardDataList = new List<CardData>();
public class CardData
{
public string cardType { get; set; }
public int cardColor { get; set; }
}
static void Main(string[] args){
Console.WriteLine(this.cardDataList.FirstOrDefault().CardType);
}
// another function should be called before the printing
public void MyAddFunction()
{
cardDataList.Add(new CardData() { cardType = boxLine1, cardColor = randColor });
}
public List<CardData> MyAddFunction()
{
var cardDataList = new List<CardData>();
cardDataList.Add(new CardData() { cardType = boxLine1, cardColor = randColor });
return cardDataList;
}
static void Main(string[] args){
this.cardDataList = MyAddFunction();
Console.WriteLine(this.cardDataList.FirstOrDefault().CardType);
}
static void Main(string[] args){
var yourKeyword = "...Whatever";
var theObjectYouWant = this.cardDataList.FirstOrDefault(x => x.CardType.StartsWith(yourKeyword));
// the theObjectYouWant should contain the first match item or null in case of no match
Console.WriteLine(theObjectYouWant.CardType);
}