Search code examples
c#variablesformatting

How can I extract an int, from (int, int) format variable? It says I can't use indexing


I'm working on a NeuralNet and I decided to store the edges (connections) of the network in format (int,int) edge. I used it because it's very easy to add it to a list List<(int,int)> listOfConnections

I've already implemented this variable in multiple places in my code and only now I've realized I'm not sure how to access each int separately. When I try edge[0] i get an error that I can't use indexing in this type of variable.

Any ideas how can I pull out the first and second ints separately? Also what's the name of this form of variable? It's not Touple, not a Vector, if I knew the name maybe I could find more information on how to use it.


Solution

  • You've created a ValueTuple.

    You can access the first item with edge.Item1 and the second with edge.Item2.

    .NET Fiddle Example