C
C#3y 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
DownOP3y ago
hmm tuple you say like this? ctor(Tuple<double, double> pointA)?
sibber
sibber3y ago
thats the old syntax ctor((double, double) pointA)
Down
DownOP3y ago
a okay
sibber
sibber3y ago
doesnt the bcl have a point type?
Down
DownOP3y ago
and how do i then send it initialize or sum var x = new smth(...) a okay thanks
sibber
sibber3y 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
DownOP3y ago
thanks but cant use it for now
sibber
sibber3y ago
doesnt take a double tho id make a record struct
Down
DownOP3y 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
MODiX3y 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
DownOP3y ago
yea
sibber
sibber3y ago
wdym like pass a tuple to a method that expects seperate args? no i dont think thats possible
Down
DownOP3y 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
sibber3y ago
also you cant index tuples
Down
DownOP3y ago
o so how do i access values
sibber
sibber3y ago
either name the values, or .Item1, .Item2 etc
Tvde1
Tvde13y ago
You can make your own
public readonly record struct Point(double X, double Y);
public readonly record struct Point(double X, double Y);
Want results from more Discord servers?
Add your server