question

joshBAUER-1782 avatar image
0 Votes"
joshBAUER-1782 asked KyleXu-MSFT action

c++ or c# class opening

I used to write:

 window.size.X=19;
 window.size.Y=39;
 window.location.X=29;
 window.location.Y=79;

But it would be much easier to open class before modyfing it like:

 window{
     size{
         X=19;
         Y=39;
     }
     location{
         X=29;
         Y=79;
     }
 }

That would reduce code size ,it would read more easily and clearly
and take much less disc space.
Words are not repeating that many times.

Is class opening like one in example above possible in c++ or c#?
Is there any language that would allow class opening?


dotnet-csharp
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

vb2ae avatar image
1 Vote"
vb2ae answered PiotrRybak-7170 commented

I dont think you can use that exact syntax but you could do something like this in C#. I used the WPF window class not exactly the same as yours

         Window window = new Window()
         {
             RenderSize = new Size()
             {
                 Height = 100,
                 Width = 200
             },
             WindowStartupLocation = WindowStartupLocation.CenterScreen
         };
· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I knew that I could do that for constructors

BUT I did not know any way to do that for existing already classes.

0 Votes 0 ·

@joshBAUER-1782
This has nothing to do with the constructor. Please note that the assignment statement is written in curly braces instead of parentheses.
Please check the documentation: Object and Collection Initializers (C# Programming Guide)

0 Votes 0 ·

What is any link to any tutorial for submitting c# language development proposal?

0 Votes 0 ·

@PiotrRybak-7170
Do you mean you want to make some suggestions for C#?
If so, then you can do it in the Developer Community.

0 Votes 0 ·