I have List with n items. I wish transform my list to new list, in which no more than n first items.
Example for n=3:
[1, 2, 3, 4, 5] => [1, 2, 3]
[1, 2] => [1, 2]
What is the shortest way to do this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you have C# 3, use the
Takeextension method:See: http://msdn.microsoft.com/en-us/library/bb503062.aspx
If you have C# 2, you could write the equivalent:
The only difference is that it isn’t an extension method: