Suggestion: hidden/implicit tuple to ctor operator. #3898
Unanswered
Redageddon
asked this question in
General
Replies: 1 comment 7 replies
-
C# 9.0 will bring target-typed using System;
public class TestClass {
public TestClass(int x, string y) { }
}
public static class Program {
public static void Main() {
TestClass single = new(0, "zero");
var asd = new TestClass[] {
new(1, "one"),
new(2, "two"),
new(3, "three"),
new(4, "four"),
new(5, "five")
};
}
} Beyond that I think I'd rather have a way to "splat" a tuple into arguments to a constructor or method rather than something specific to implicitly convert from a tuple to a constructor of a type. |
Beta Was this translation helpful? Give feedback.
7 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
OK, so every class that has a ctor with more than 1 argument should contain a hidden implicit conversion from a tupple matching every ctor. See image for example.




This would allow for many different things (this idea i got from the implicit new from c# 9, i was just thinking i could take it a step further) such as,
or
But wait, you might be saying, what if i want to define my own ctor that takes in a tuple.
Answer: That is why the operator should be hidden.
This would be like if you had a child class override a virtual method. But, you don't actually call override on the operator or anything like that, it just would use the implemented one instead of the default hidden one. What i mean by hidden is that you dont actually see and cant edit it, the only way to change what it is, is to provide an implementation yourself. That is, yet again, the same as how a child class could use a virtual method from a parent class without actually having to override or implement it.
Beta Was this translation helpful? Give feedback.
All reactions