0

I have the following:

var resourceids = racks.Select(a => a.Technology.IT360ID.Value);
var resource = repository.GetResources(resourceids);

But i am not sure how i can convert the var resourceids to long[] as my repository method accept long[]

2 Answers 2

4

Assuming a.Technology.IT360ID.Value is a long then resourceids is actually an IEnumerable<long>. So you just need to convert it using ToArray():

var resourceids = racks.Select(a => a.Technology.IT360ID.Value).ToArray();
var resource = repository.GetResources(resourceids);

Remember that var is not a "type" - it just lets the compiler determine the type versus declaring it explicitly.

This may be a case where it's better to explicitly declare the type versus using var:

long[] resourceids = racks.Select(a => a.Technology.IT360ID.Value).ToArray();
var resource = repository.GetResources(resourceids);
1

The method Select will return IEnumerable<long>. So, to convert to long[], you can call ToArray() which forces immediate query evaluation and returns an array that contains the query results:

var resourceids = racks.Select(a => a.Technology.IT360ID.Value)
                       .ToArray();

var resource = repository.GetResources(resourceids);

Your Answer

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