c++ or c# class opening

josh BAUER 166 Reputation points
2021-03-14T16:17:25.16+00:00

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?

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,223 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Ken Tucker 5,846 Reputation points
    2021-03-14T18:31:52.89+00:00

    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
            };
    
    1 person found this answer helpful.