Accessing an item of a tuple of a list of a method of a class

I made a list of tuples and I can’t understand why I can’t access it in other methods.
Bing Chat says something about Static and InnerClass and OuterClass and Program.
It must represent the basic Closest Point component (12.8 KB)

private void RunScript(List pList, ref object SortedPoints, ref object SortedIndices, ref object SortedDistances)

ClosestsPoints sortedPoints = new ClosestsPoints(pList[0], pList, 10);
SortedPoints = sortedPoints.calculate();



public class ClosestsPoints
public Point3d p;
public List c;
public int n;

public ClosestsPoints(Point3d point, List<Point3d> cloud, int count)
  p = point;
  c = cloud;
  n = count;

public IList<Tuple<double, double, double, int, double>> calculate() // it should just be done when the class is made
  List<Point3d> closestPnts = c.ToList();
  closestPnts = closestPnts.OrderBy(pn => pn.DistanceTo(p)).ToList();

  int[] array = {n, closestPnts.Count};
  int limit = array.Min();

  List<int> closestIndices = new List<int>();
  for(int i = 0; i < limit;i++)
    Point3d pn = closestPnts[i];
    int id = c.IndexOf(pn);

  List<double> closestDistances = new List<double>();
  for(int i = 0; i < limit; i++)
    Point3d pn = closestPnts[i];
  // a tuple output because a method cannot return the lists ClosestPoints, ClosestIndices, ClosestDistances
  List<Tuple<double, double, double, int, double>> data = new List<Tuple<double, double, double, int, double>>();
  for (int i = 0; i < limit; i++)
    data.Add(Tuple.Create(closestPnts[i].X, closestPnts[i].Y, closestPnts[i].Z, closestIndices[i], closestDistances[i]));
  return data;

public List<int> ClosestPoints (List<Tuple<double, double, double, int, double>> data) // i made a new method
  List<Point3d> closestsPoints = new List<Point3d>();
  foreach (object tuple in data)
    closestsPoints.Add(new Poitn3d(tuple.Item1, tuple.Item2, tuple.Item3));
  return closestsPoints;

public List<Point3d> ClosestIndices (List<Tuple<double, double, double, int, double>> data)
  List<int> closestIndices = new List<int>();
  foreach (object tuple in data)
    closestIndices.Add(new int(tuple.Item4));
  return closestIndices;

public List<double> ClosestDistances (List<Tuple<double, double, double, int, double>> data)
  List<double> closestDistances = new List<int>();
  foreach (object tuple in data)
    closestDistances.Add(new int(tuple.Item5));
  return closestDistances;


// </Custom additional code>

Instead of using ultra pointless resources (ideal for lobotomy) read some proper C# book (many times as I said many times). Meaning: if you want to play with classes (not required for this case) learn in depth what they are.

Other than that if you want to “assosiate” points with N closest ones (and their indices … meaning VV, VE, EV Conn Trees + Island detection etc etc) like we do in proximity Graphs … use a Point3dList or a RTree.

Other than that the IndexOf thingy is (for obvious reasons) kinda a Harley Davidson.

Other than that if your Universe is the R/GH combo … use DataTrees. The impact in performance (VS other collections) is not worth talking unless you have a zillion points on hand (but who does that sort of thing? why?). Plus … well … in order to read some collection from one C# to some other (real life) … the unboxing part has a cost that negates … well … you can understand what.

Moral: if you want to ride fast … tune your suspension (and forget ponies).

Thank you for your response. Very friendly you still want to respond to my questions :grimacing:

Yes I read a C# book and I cannot find anything on it.
The internet says that if you want to return multiple items that I can make a list of tuples instead.

I learn it now this way. Return a list of tuples.
And to my reasoning I should use another method in order to extract the data and turn things to Point3d for example.
And how I see it, with using N I can limit the calculation time.

I don’t know what is meant with non-static. This is what I see when I shorten the code to extract from the tuple the data for a Point3d.

Should I seperate it in 2 classes. 1 class with code and 1 class to run the code
Or should I do something with puting the term static somewhere?

Wrong book I assume: classes are the core of the matter in object oriented coding … meaning the obvious: BEFORE using’m MASTER them.

NEVER use Internet for answers (not to mention #@%@$ A.I. thing(s)): IF your goal is to become some sort of pro (think the dollars as well if books is not your thing or you are addicted to Internet).

Other than that:

  1. Nobody writes a single C# to address some pragmatic (*) task in real-life. This means that one C# talks to another. If the collections used require unboxing (like, say, the content of any custom class defined in a given C#) … then the argument of performance is pointless. But … well … if the goal is related with data mining (i.e. simple or nested P/LINQ ) then … custom types are a must (life sucks).

  2. When you post something ALWAYS declare your “final” goal: for instance if you are after prox Graphs the whole approach is wrong: because prox Graps are about connectivity => see 1.

  3. Calculation time in ONE C# means nothing. The total time for doing something realistic (meaning lot’s of C#''s => see 1) means everything. If on the other hand something is slow … blame in most of cases yourself (and NEVER buy a faster computer: unless you are after Black Holes, Planet Collisions, Dark Matter, CFD for Formula1 and similar things).

So … let’s start form point zero: what exactly is your goal? (Graphs? Cats? Dogs? Something?).

BTW: I hate Internet, computers, Windows, Doors, .NET, .NOT etc etc.

(*) this for instance is a pragmatic thing: does stand alone module trusses where their components are torsion free (~2500 lines of code). If we skip the fact that these C#'s (and notably their Methods) are written by many … imagine doing a single C# that does that.

Do this:

Write a letter to some stupid A.I. thing:

Dear Ultimate Hope (of all Hopes). I’m a novice who refuses to follow Lord’s instructions for learning C#. In fact I can’t understand what he’s talking about. Anyway … my goal is to do some prox Graphs and their connectivity trees. I do hope - Dear Ultimate Hope - that you know what these things are. Can You - Dear Ultimate Hope - help me?

PS: Can You - Dear Ultimate Hope - guide me to find islands based solely on VV connectivity?

Yours truly.

Wait a million years (time flies) for some answer.

In the mean time: (133.0 KB)

I want to make 1 class
I want to make a method producing 1 list of tuples
I want to use that list in another method by extracting
Everything in 1 class, making the dataset, editing the dataset, output the data

In my case
Making the dataset with the 1st method
Editing the dataset with the 2nd method
Whereafter the dataset can be output or even being edited by an 3th method


Well … gave you enough time to evaluate your C# sins (a lot).

Of course I have Classes with Tuples examples/tutorials …

… but in order to get these you should post:

a Declaration of C# Obedience:

Lord forgive me for at times treating You irreverently. Forgive me where I have not glorified Your name and Your C# suggestions by my actions and lifestyle. Lord, forgive me for (list explicitly all C# crimes that you have committed) … blah, blah.

1 Like


No! And thank you :slight_smile:
Can I view the file I am very interested :slight_smile:

Can you upload the file? Thank you in advance.