Navigating API Explorer In Code

Hi guys,

I’ve had a look through the sample code and am a little less familiar with C# than with some other languages. I’m just looking for some very simple code to extract certain information from the API Explorer and output it into the log. I work best by looking at examples - But the code examples I’ve seen (the 0km autopilot and the miner) are either a little short or lacking from what I want.

So I’ve broken apart the 0km warper to a fairly simple script that loops every 4 seconds and invalidates the MemoryMeasurementParsed. I’ve kept Measurement, and am trying to follow the object down to the data I need.

Now in this case I’m simply looking to get the label text for all the entries inside the Probe Scanner window. Being familiar with Javascript, this is how I would lay it out based on what I see in the API Explorer:

var Measurement = Sanderling?.MemoryMeasurementParsed?.Value;
var temp = Measurement.WindowProbeScanner[0].ScanResultView.Entry; //This is the array containing the entires

for (var i = 0; i < temp.length; i++) {
	Host.Log(temp[i].LabelText[2].Text); //Will simply output the text of each site

So the first error I get is trying to access [0] of the WindowProbeScanner array (is it actually an array? It acts like one in the API explorer). Apparently it’s actually an “IEnumerable” but I’m not sure how to access the data in that.

Apologies if this is a really stupid C# question, I’m not even sure what to Google since you seem to be using your own types and I’m really not sure where to go from here.

Thanks in advance.

Edit: Oh! I think I may have found it - The ElementAtOrDefault() function, and also I need to use ?. instead of … I’ll give that shot tomorrow when I get up.

It might be a CLR array, but do not depend on such an assumption.

Yes, using ElementAtOrDefault(index) is the default way to get an element from that sequence.

Using that method works as long as type of the expression on the left is an instance of the generic type IEnumerable<>.

Both the method and the generic type are part of Microsofts Framework so you will find those on google well.

This substitution is to avoid intransparency of control flow by implicitly throwing exceptions. This is a problem of C#. You might already have encountered the same problem when using javascript.

Thank you very much for the explanation - I seem to understand what’s going on quite a bit better now and have started writing my own ratting script :). It’s taken a little bit of work to migrate into the C# mindset but I’m getting there.