I want to plus 3 to all list<int> member without using for loop or foreach loop ? Can I do this in one line ?How?
I want to plus 3 to all list<int> member without using for loop or
Share
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.
Something somewhere is going to have to loop. You don’t have to loop in your code, but something’s going to have to.
I can’t think of anything offhand which will modify all the elements in a list, but using LINQ you could create a new
List<int>easily:or pre-LINQ (and slightly more efficient, but also more
List<T>-specific):But both of these will be looping behind the scenes.
You could potentially create a projecting
IList<T>implementation which lazily applied a projection (or possibly a bijection if you wanted to be really fancy)… but that would be significant amounts of work.