However, a few patterns aren??™t as obvious but can
still be powerful when you??™re used to them. We??™ll explore two of these patterns in our
next section. This is more for the sake of interest than as part of learning about the
behavior of nullable types themselves??”you now have all the tools you need to use
them in your own code. If you??™re interested in quirky ideas and perhaps trying something
new, however, read on??¦
4.4 Novel uses of nullable types
Before nullable types became a reality, I saw lots of people effectively asking for them,
usually related to database access. That??™s not the only use they can be put to, however.
The patterns presented in this section are slightly unconventional but can make code
simpler. If you only ever stick to ???normal??? idioms of C#, that??™s absolutely fine??”this section
might not be for you, and I have a lot of sympathy with that point of view. I usually
prefer simple code over code that is ???clever?????”but if a whole pattern provides benefits
when it??™s known, that sometimes makes the pattern worth learning. Whether or not
you use these techniques is of course entirely up to you??”but you may find that they
suggest other ideas to use elsewhere in your code. Without further ado, let??™s start with
an alternative to the TryXXX pattern mentioned in section 3.2.6.
4.4.1 Trying an operation without using output parameters
The pattern of using a return value to say whether or not an operation worked, and
an output parameter to return the real result, is becoming an increasingly common
one in the .
Pages:
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276