elena1234

Collection with different types of classes

Apr 16th, 2021 (edited)
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.38 KB | None | 0 0
  1.  private ICollection<Type> foodTypes = new List<Type> { typeof(Vegetable), typeof(Fruit) };
  2.  
  3.  
  4. // if (!foodTypes.Any(f => f.Name == food.GetType().Name))
  5.             {
  6.                 string exceptionMessages = String.Format(ExceptionMessages.InvalidFoodException, this.GetType().Name, food.GetType().Name);
  7.                 throw new ArgumentException(exceptionMessages);
  8.             }
Add Comment
Please, Sign In to add comment