4 ms·
I'm not sure if it's what you mean, but can't you have all your properties without a setter, and only init them inside the constructor for example ? Would your
by bilekas 11mo ago
I'm not sure if it's what you mean, but can't you have all your properties without a setter, and only init them inside the constructor for example ?
Would your 'readonly' annotation dictate that at compile time ?
eg
class Test {
private readonly string _testString {get;}
public Test(string tstSrting)
=> _testString = tstSrting ;
}
We may be going off topic though. As I understand objects in typescript/js are explicitly mutable as expected to be via the interpertor. But will try and play with it.
- vips7L 11mo agoI think you would want to use an init only property for your example class Test { public string Test { get; init; } } I'm not a C# expert though, and there seems to be many ways to do the same thing.
- bilekas 11mo agoI don't use the init decorator myself but I would hazard a guess it's similar. Don't quote me on that though. The point does stand though, outside of modifying properties I'm not sure what a "private" class itself achieves.
- vips7L 11mo ago> I don't use the init decorator myself but I would hazard a guess it's similar. Genuinely curious, why not? Seems to be less verbose. I don’t write C#s so I’m not sure of the downsides of any particular feature.