C
C#2y ago
Down

how can i accept only array of 2 doubles?

tried this but i get error public SomeConstructor(double[2] pointA)
17 Replies
Down
Down2y ago
hmm tuple you say like this? ctor(Tuple<double, double> pointA)?
sibber
sibber2y ago
thats the old syntax ctor((double, double) pointA)
Down
Down2y ago
a okay
sibber
sibber2y ago
doesnt the bcl have a point type?
Down
Down2y ago
and how do i then send it initialize or sum var x = new smth(...) a okay thanks
sibber
sibber2y ago
Point Struct (System.Drawing)
Represents an ordered pair of integer x- and y-coordinates that defines a point in a two-dimensional plane.
Down
Down2y ago
thanks but cant use it for now
sibber
sibber2y ago
doesnt take a double tho id make a record struct
Down
Down2y ago
also 1 more question is there a way to like unpack a tuple? something like *tuple in python or ...tuple in type script @Cyberrex ?
MODiX
MODiX2y ago
Cyberrex#8052
REPL Result: Success
(int, double) t = (1, 0.5);
(int i, double d) = t;
d
(int, double) t = (1, 0.5);
(int i, double d) = t;
d
Result: double
0.5
0.5
Compile: 489.061ms | Execution: 44.580ms | React with ❌ to remove this embed.
Down
Down2y ago
yea
sibber
sibber2y ago
wdym like pass a tuple to a method that expects seperate args? no i dont think thats possible
Down
Down2y ago
public void Method1(double arg1, double arg2) ...

Method1(tuple[0], tuple[1])
Method1(...) unpack tuple there
public void Method1(double arg1, double arg2) ...

Method1(tuple[0], tuple[1])
Method1(...) unpack tuple there
okay
sibber
sibber2y ago
also you cant index tuples
Down
Down2y ago
o so how do i access values
sibber
sibber2y ago
either name the values, or .Item1, .Item2 etc
Tvde1
Tvde12y ago
You can make your own
public readonly record struct Point(double X, double Y);
public readonly record struct Point(double X, double Y);