Prev | Current Page 391 | Next

Jon Skeet

"C# in Depth: What you need to master C# 2 and 3"


The considerations I??™ll discuss in this chapter (and indeed in the rest of the book)
will rarely be black and white. Perhaps more than ever before, readability is in the eye
of the beholder??”and as you become more comfortable with the new features, they??™re
likely to become more readable to you. I should stress, however, that unless you have
good reason to suppose you??™ll be the only one to ever read your code, you should consider
the needs and views of your colleagues carefully.
Enough navel gazing for the moment. We??™ll start off with a feature that shouldn??™t
cause any controversy??”and that I always miss when coding in C# 2. Simple but effective,
automatically implemented properties just make life better.
8.1 Automatically implemented properties
Our first feature is probably the simplest in the whole of C# 3. In fact, it??™s even simpler
than any of the new features in C# 2. Despite that??”or possibly because of that??”it??™s also
immediately applicable in many, many situations. When you read about iterator blocks
in chapter 6, you may not immediately have thought of any areas of your current codebase
that could be improved by using them, but I??™d be surprised to find any nontrivial
C# program that couldn??™t be modified to use automatically implemented properties.
This fabulously simple feature allows you to express trivial properties with less code
than before.


Pages:
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403