To all
A general question about programming. I came across the Enumerable.Min Method from
https://msdn.microsoft.com/en-us/library/system.linq.enumerable_methods....
As I am using /extracting a lot of array from NX.CAE I thought some of the options could be of interest. The 2 I am interested are the .Max() and the .Min(). When I tried the example provided on the web page, see below, I got the error: 'Min' is not a member of 'system.array'
Dim inputdoubles() As Double = {1.5E+104, 9.0E+103, -2.0E+103}
' Determine the smallest number in the array.
Dim minvalue As Double = inputdoubles.Min()
theLW.WriteLine("-Min is : " & minvalue.ToString)
Q:
Can these options be used in NX programming?
Is there an option to return the rank of the max/min value?
Thanks
Regards
JXB
re: linq extension methods
To the best of my knowledge, the LINQ extension methods can only be used if you have an author license and you are compiling the code.
However, arrays do provide a Sort method. After sorting an array, the smallest/largest values will be the first/last element of the array.
re: linq extension methods
Thanks for that
I did try adding 'Imports System.Linq' but there was not specific error message. Maybe the message I am getting is related to that. I am only looking at "smarter" ways of doing my small codes. As I am not a programmer so more often than not a brute force approach works. In this case my Getmaxmin() function works (the function does a bit more than searching for the max/min (just!)). I did originally thought of sorting the array but I need to know the rank of the max/min value so that "associated" values (in other arrays) at that rank can be extracted.
Thanks
Regards
LINQ extension methods
People often confuse "Imports" with references.
Adding a reference to System.Linq lets you use the functions in System.Linq. However, if you're writing code in the Journal Editor, you can't add this reference. Code in the Journal Editor has a small set of built-in references, and System.Linq is not one of them.
Writing "Imports System.Linq" just lets you use abbreviated names for functions in System.Linq.
But, if you don't have a reference to System.Linq neither the full names nor the abbreviated ones will work.
And, anyway, System.Linq doesn't have a function that gives you the index of the largest (or smallest) item in a collection.
There are functions in Snap that do exactly what you want: Snap.Math.MaxIndex and Snap.Math.MinIndex.
RE: LINQ extension methods
Thanks for the clarification ciao. Much appreciated. Will have to have a look at SNAP again. I did when I started playing with programming with NX but I have since neglected it.
the functins Snap.Math.MaxIndex and Snap.Math.MinIndex are indeed likely to do what I need. I wrote my own function to do it as I wanted to get the max/min value as well as the ranks! If I can use the SNAP stuff then it will make my own function irrelevant and simplify-ish the code.
Will have to re-read the "intro to SNAP" and the reference guide as 1st test using max and MaxIndex (in a simple .vb) failed. Probably to early and I need a coffee 1st!
Thanks
Regards
JXB
Thanks
Regards
Snap.Math.MinIndex
I don't think these functions are mentioned in the SNAP Getting Started guide, and there is no example code in the ref guide, either. These functions are so simple that they are supposed to be self-explanatory, I suppose. If you have your own functions, and they work, I don't know that there's any strong reason to switch to the SNAP ones.
RE: Snap.Math.MinIndex
Agree with you if it's working don't touch it. I have an eye on rev2 of the code when I may implement a new user option. In any case I do not believe I have the SNAP licence
Thanks
Regards