Datasheet

7
Chapter 1: Defi ning the Language Environment
Unfortunately, you still have the vast array of native-code applications to consider when designing your
applications. You may need to access Windows directly to perform some tasks or work with an older DLL
where pointer manipulation is required. When you encounter this situation, you have two choices. You
could wrap the code you need in a C++ DLL and make it available to your applications using P/Invoke in
a manner that doesn’t require the use of unsafe code. The second choice is to work with the older code
directly and place the pointer code within an unsafe code block. C# is one of the few managed lan-
guages that let you use unsafe code blocks. You can fi nd a useful tutorial on using unsafe code blocks at
http://www.csharp-tutorials.com/unsafe-code-execution/.
In-Depth Debugging
Generally, you’ll nd that the C# debugger provides more information than the Visual Basic debug-
ger, provided youre working with the same application in both debuggers. This section also bases its
appraisal of C# on the use of the Microsoft debugger. If you use a third-party product, you may fi nd
that it provides more or less capability than the Microsoft product.
Some things work the same between Visual Basic and C# — a loop is still a loop. However, you’ll
notice a difference when working with some complex development problems. For example, a Language
Integrated Query (LINQ) call in C# always shows every step of the process used to create the query
results. In some cases, Visual Basic shortcuts the process and shows only a few of the steps, making it
harder to diagnose problems with your LINQ statement.
Of course, the question is whether you always need the complete attention that C# provides. The answer
depends on your application. As application complexity increases and you use more advanced language
features, the requirement for a debugger that provides in-depth information also increases.
The debugging differences with other languages extend to other needs. C# usually makes it easy to
drill down into an object to any level. This accessibility means that you spend less time trying to fi gure
out what an object actually contains. In some cases, you have to work hard with other languages to
determine what an object contains, especially when an object resides within another object.
Additional IntelliSense Functionality
When you create your own applications, you can use the triple comment /// symbol in C# to create a
documentation block where you fi ll out information for various application elements such as classes
and functions. Visual Basic.NET 2008 adds this feature as the
‘’’ symbol. After you add these special
code blocks, you can set the compiler to create an eXtensible Markup Language (XML) fi le containing
detailed information about your application. However, C# still provides superior IntelliSense support
for these special XML fi les, which means that C# provides better IntelliSense support for the code you
write.
C# also provides multiline comments, a feature it shares with C++. If you want to create a multiline
comment for Visual Basic, you must start each comment line individually.
Coding Additions
C# supports a number of coding additions — features that you won’t necessarily fi nd in other managed
development languages. One of the more useful is the availability of strong iterator support, including
the
yield keyword. When an application iterates a collection, the yield keyword helps the developer
control how the iteration occurs and can stop the iteration as needed.
15962c01.indd 715962c01.indd 7 1/23/09 5:44:59 AM1/23/09 5:44:59 AM