-1

I have the following Guids received from client in an array.

Question: How i can take count of the unique Guids showing after '_' from the following array.

0: "5146d57a-701d-e511-82ee-303a64efb676_6544d57a-701d-e511-82ee-303a64efb676"
1: "5546d57a-701d-e511-82ee-303a64efb676_6544d57a-701d-e511-82ee-303a64efb676"
2: "5346d57a-701d-e511-82ee-303a64efb676_6544d57a-701d-e511-82ee-303a64efb676"

3: "5146d57a-701d-e511-82ee-303a64efb676_6644d57a-701d-e511-82ee-303a64efb676"
4: "5546d57a-701d-e511-82ee-303a64efb676_6644d57a-701d-e511-82ee-303a64efb676"
5: "5346d57a-701d-e511-82ee-303a64efb676_6644d57a-701d-e511-82ee-303a64efb676"

6: "5146d57a-701d-e511-82ee-303a64efb676_6744d57a-701d-e511-82ee-303a64efb676"
7: "5546d57a-701d-e511-82ee-303a64efb676_6744d57a-701d-e511-82ee-303a64efb676"
8: "5346d57a-701d-e511-82ee-303a64efb676_6744d57a-701d-e511-82ee-303a64efb676"
3
  • post what have you tried and the problem you are facing instead of asking for a readymade solution. Commented Jun 28, 2015 at 10:05
  • 1
    Solution alredy provided : stackoverflow.com/q/1388361/3711660 Commented Jun 28, 2015 at 10:05
  • A dictionary and string.split would come in handy. Commented Jun 28, 2015 at 10:06

1 Answer 1

2

If your input is some implementation of IEnumerable<string> (e.g. array or list):

int count = input.Select(line => line.Split('_').Last()).Distinct().Count();

This splits each line at the _ character, takes only the last part and counts the distinct parts.

Sign up to request clarification or add additional context in comments.

3 Comments

Implementation is public List<Guid> Ids { get; set; }
Your answer shows a list of two guids per line, that can't be a List<Guid>.
you're right. I change implementation from Guid to string and it gives the require result. thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.