Replies: 8 comments
-
I much prefer |
Beta Was this translation helpful? Give feedback.
-
@jnm2 it's simple when it's only one character, but imagine when you have |
Beta Was this translation helpful? Give feedback.
-
I'd still prefer the statement body in that case. public static void M1(this A a, int x, int y) => a { x = x, y = y }; |
Beta Was this translation helpful? Give feedback.
-
@jnm2 my proposal would also allow the following to be achieved: public static void M1(this A a, (int x, int y) t) => a.(x, y) = t; Since initializers doesn't support multiple assignments (like public static void M1(this A a, (int x, int y) t) => a { x = t.x, y = t.y }; Again: it's simple when it's only one character, but imagine when |
Beta Was this translation helpful? Give feedback.
-
With methods defined in the class you can already use tuple syntax to make concise assignment statements to fields/properties. public class A
{
int _x;
int _y;
public A(int x, int y) => (_x, _y) = (x, y);
} Thanks, @MadsTorgersen for pointing this out. If the new syntax for "extension classes" is adopted, you should be able to use this technique in that context as well. |
Beta Was this translation helpful? Give feedback.
-
@MgSam You're right, but that's valid only for extension methods. I used extension methods in my example to make it simple, but that's not always the case. You solution is partial and relies on a feature that's not yet implemented (and it's not a certainty that it will be), just like @jnm2's. |
Beta Was this translation helpful? Give feedback.
-
Hey now, I haven't presented a solution because I'm not convinced there's a problem. 😉 Just bringing proposals in the same mental space to attention. |
Beta Was this translation helpful? Give feedback.
-
@Logerfo My example is valid inside of all classes today as we speak. I was saying it is not currently applicable to extension methods, but that might change with the proposed "extension everything" feature. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I couldn't find something similar to this, hope it's not duplicate.
Would the syntax below be achievable?
Beta Was this translation helpful? Give feedback.
All reactions