I know that to create a tuple in C#, we use the format:
Tuple <int,int>from = new Tuple<int,int>(50,350); Tuple <int,int>to = new Tuple<int,int>(50,650);
where each tuple is a coordinate pair. I am trying to create an array of multiple coordinate pairs using tuples. Could someone help me out on this?
EDIT: This is what I have tried so far. I want it to be in this array format only.
Tuple<int, int>[] coords = new Tuple<int,int>({50,350},{50,650},{450,650});
Compiler complains that there is something wrong.. Please tell me what it is?
In JavaScript, tuples are created using arrays. In Flow you can create tuples using the [type, type, type] syntax. When you are getting a value from a tuple at a specific index, it will return the type at that index.
Create a tuple class, something like: class Tuple { private Object[] data; public Tuple (Object.. members) { this. data = members; } public void get(int index) { return data[index]; } public int getSize() { ... } }
in C# 7
var coords = new[] { ( 50, 350 ), ( 50, 650 ), ( 450, 650 )};
for named version, do this: (thanks entiat)
var coords2 = new(int X, int Y) [] { (50, 350), (50, 650), (450, 650) };
or
(int X, int Y) [] coords3 = new [] { (50, 350), (50, 650), (450, 650) };
or
(int X, int Y) [] coords4 = { (50, 350), (50, 650), (450, 650) };
so we can use X, Y instead of Item1, Item2
coords4.Select(t => $"Area = {t.X * t.Y}");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With