0

I want to make sure that all items in a collection to be different. How to do that?

Let's say:

IEnumerable collection = new[] { 1, 2, 5, 8 };

collection.Should().BeAllDifferent(); // NOTE: BeAllDifferent doesn't exist
mousetail
  • 4,536
  • 2
  • 18
  • 36
  • 1
    There's nothing built-in to FA to do that check for you. You can perform the logic in the link above to check if the distinct count is equal to the original count, or make your own custom extension method (which does the same thing) – gunr2171 Nov 04 '21 at 14:51
  • The linked solution is perfectly fine (and kinda neat), thanks. It basically turns the problem upside down. – Albert Takács Nov 04 '21 at 14:55
  • @gunr2171, The linked question helps, but it doesn't answer it, which is why you had to add to actually answer it in your second comment. Please don't vote to close questions which require a comment or answer to answer because the other Q&A doesn't actually answer the question! – ikegami Nov 04 '21 at 14:57
  • Link to original dupe target for reference: https://stackoverflow.com/questions/18303897/test-if-all-values-in-a-list-are-unique?noredirect=1&lq=1 – mousetail Nov 09 '21 at 10:29

0 Answers0