KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Apparently you can change the this value from anywhere in your struct (but not in classes): struct Point { public Point(int x, int y) { this = new Point(); X = x; Y = y; } int X; int Y; } I've neither seen this before nor ever needed it. Why would one ever want to do that? Eric Lippert reminds us that a feature must be justified to be implemented. What great use case could justify this? Are there any scenarios where this is invaluable? I couldn't find any documentation on it 1 . Also, for calling constructors there is already a better known alternative syntax, so this feature is sometimes redundant: public Point(int x, int y) : this() { X = x; Y = y; } I found this feature in an example in Jeffrey Richter's CLR via C# 4th edition . 1) Apparently it is in the C# specification .
Tags (comma-separated)
Save Edits
Cancel