Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

How do I call a string inside a different class

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 });
}
Comment

How do I call a string inside a different class

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);
}
Comment

How do I call a string inside a different class

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);
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: Unity Input Key Message 
Csharp :: set time on audio source unity 
Csharp :: How to build a rest component with very long process 
Csharp :: how to make diagonal movement not double the speed of the player in unity 
Csharp :: c# webbrowser upload file 
Csharp :: selecteditem treeview wpf 
Csharp :: c# create default instance of type 
Csharp :: C# Datagridview Column Header Double Click 
Csharp :: Calculate relative time in C# 
Csharp :: function to accept interger 
Csharp :: optional parameter get request c# 
Csharp :: c# iterate xml 
Csharp :: mesh decimate pyvista 
Csharp :: pcamera 
Csharp :: c# panel to graphics 
Csharp :: get link element revit api 
Csharp :: conditional middleware .net core 
Csharp :: classe padre figlio c# 
Csharp :: Zxing Xamarin use front Camera 
Csharp :: C# How to implement IEnumerable<T interface 
Csharp :: c# convert address to int 
Csharp :: c# load button image from resource 
Csharp :: virtual list entity framework 
Csharp :: dispose await task c# 
Csharp :: how to check that a gameobject touches a colour in unity c# 
Csharp :: system.collections.generic.list 1 system.int32 c# 
Csharp :: IAuthorizationFilter OnAuthorization AuthorizationContext MyAuthorizeAttribute HttpUnauthorizedResult HttpContext 
Csharp :: is and as in c# 
Csharp :: instance vs initiate 
Csharp :: c# getdecimal null 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =