Reputation: 211
So for instance if I've an array of an object with the properties "Distance" and "Origin" is there any quick way of getting an array of just the distance property from that array without having to do:
float[] distances = new float[objectArray.Length] ();
for (int i; i < objectArray.Length; i++)
{
distances[i] = objectArray[i].Distance;
}
Upvotes: 0
Views: 79
Reputation: 25897
You need to use LINQ projection query as shown below:
//use this namespace at the top of your code file
using System.Linq;
//inside your method. Replace the entire code in your post with this.
var distances = objectArray.Select(x => x.Distance).ToArray();
Upvotes: 2