Beispiel #1
0
 public string SellStock(string companyName, decimal sellPrice)
 {
     if (!Portfolio.ContainsKey(companyName))
     {
         return($"{companyName} does not exist.");
     }
     else
     {
         if (sellPrice < Portfolio[companyName].PricePerShare)
         {
             return($"Cannot sell {companyName}.");
         }
         else
         {
             Portfolio.Remove(companyName);
             MoneyToInvest += sellPrice;
             return($"{companyName} was sold.");
         }
     }
 }
Beispiel #2
0
 public string SellStock(string companyName, decimal sellPrice)
 {
     if (Portfolio.Any(x => x.Name == companyName))
     {
         Stock currentStock = Portfolio.Where(x => x.Name == companyName).FirstOrDefault();
         if (sellPrice < currentStock.PricePerShare)
         {
             return($"Cannot sell {companyName}.");
         }
         else
         {
             Portfolio.Remove(currentStock);
             MoneyToInvest += sellPrice;
             return($"{companyName} was sold.");
         }
     }
     else
     {
         return($"{companyName} does not exist.");
     }
 }