3


I've have this piece of code in C# which convert from one array to another:

IWebElement[] elements = Self.FindChildren()
Step[] steps = new Step[elements.Length];
for (int i = 0; i < elements.Length; i++)
{
   steps[i] = new Step(elements[i]);
}

How can I write it in a shorter way (using linq or lambda expression) ?
Thanks
Omer

1 Answer 1

6

Linq approach

IWebElement[] elements = Self.FindChildren();
Step[] steps = elements.Select(x => new Step(x)).ToArray();

faster but without Linq

IWebElement[] elements = Self.FindChildren()
Step[] steps = new Step[elements.Length];
Array.Copy(elements, steps, elements.Length);
Sign up to request clarification or add additional context in comments.

Comments

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.