I know how to do this using for loops. Is it possible to do something like this using LINQ or lambdas?
int[] a = { 10, 20, 30 }; int[] b = { 2, 4, 10 }; int[] c = a * b; //resulting array should be { 20, 80, 300 }
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.
EDIT: The code below will work, but it’s not as readable as using an explicit method. LINQ is great where it definitely adds to readability… but this isn’t one of those cases.
This is a briefer version of CMS’s answer – the extra
letisn’t required, and when you’re just doing a projection it’s simpler to just use dot notation:An alternative is to use the form of Select which takes an index: