eBooks from Joseph Albahari
All books and eBooks by Joseph Albahari:
C# 4.0 Pocket Reference
Instant Help for C# 4.0 Programmers
by Joseph Albahari and Ben Albahari
typeof and Unbound Generic Types Open generic types do not exist at runtime: open generic types are closed as part of compilation. However, it is possible for an unbound generic type to exist at runtime—purely as a Type ob- ject. The only way to specify an unbound generic type in C# is with the typeof operator: class A {} class A {} ... Type a1 = typeof (A); // Unbound type Type a2 = typeof (A); // Indicates 2 type args Console.Write (a2.GetGenericArguments().Count()); // 2 You can also use the typeof operator to specify a closed type: Type a3 = typeof (A); or an open type (which is closed at runtime): class B { void X() { Type t = typeof (T); } } The default Generic Value The default keyword can be used to get the default value given a generic type parameter. The default value for a reference
(2010)
C# 3.0 Pocket Reference
Instant Help for C# 3.0 Programmers
by Joseph Albahari and Ben Albahari
Chapter 1 C# 3.0 Pocket Reference C# is a general-purpose, type-safe, object-oriented program- ming language whose goal is programmer productivity. To this end, the language balances simplicity, expressiveness, and per- formance. The C# language is platform-neutral, but it was written to work well with the Microsoft .NET Framework. C# 3.0 targets .NET Framework 3.5. What’s New in C# 3.0 C# 3.0 features are centered on Language Integrated Query capabilities, or LINQ for short. LINQ enables SQL-like que- ries to be written directly within a C# program, and checked statically for correctness. Queries can execute either locally or remotely; the .NET Framework provides LINQ-enabled APIs across local collections, remote databases, and XML. C# 3.0 features include: • Lambda expressions • Extension methods • Implicitly typed local variables • Query comprehensions • Anonymous types • Implicitly typed arrays • Object initializers • Automatic properties 1
(2008)
C# 4.0 in a Nutshell
The Definitive Reference
by Joseph Albahari and Ben Albahari
// Obtain the Console's output stream, then add that as a listener: System.IO.TextWriter tw = Console.Out; Trace.Listeners.Add (new TextWriterTraceListener (tw)); // Set up a Windows Event log source and then create/add listener. // CreateEventSource requires administrative elevation, so this would // typically be done in application setup. if (!EventLog.SourceExists ("DemoApp")) EventLog.CreateEventSource ("DemoApp", "Application"); Trace.Listeners.Add (new EventLogTraceListener ("DemoApp")); In the case of the Windows event log, messages that you write with the Write, Fail, or Assert method always display as “Information” messages in the Windows event viewer. Messages that you write via the TraceWarning and TraceError methods, however, show up as warnings or errors. TraceListener also has a Filter of type TraceFilter that you can set to control whether a message gets written to that listener. To do this, you either instantiate one of the predefined subclasses (EventTypeFilter or SourceFilter), or Diagnostics and Code Contracts subclass TraceFilter and override the ShouldTrace
(2010)
C# 3.0 in a Nutshell
A Desktop Quick Reference
by Joseph Albahari and Ben Albahari
Chapter 1Introducing C# and .NET Introducing C# and the .NET 1 Framework C# is a general-purpose, type-safe, object-oriented programming language. The goal of the language is programmer productivity. To this end, the language balances simplicity, expressiveness, and performance. The chief architect of the language since its first version is Anders Hejlsberg (creator of Turbo Pascal and architect of Delphi). The C# language is platform-neutral, but it was written to work well with the Microsoft .NET Framework. Object Orientation C# is a rich implementation of the object-orientation paradigm, which includes encapsulation, inheritance, and polymorphism. Encapsulation means creating a boundary around an object, to separate its external (public) behavior from its internal (private) implementation details. The distinctive features of C# from an object-oriented perspective are: Unified type system The fundamental building block in C# is an encapsulated unit of data and functions called a type. C# has a unified type system, where
(2008)
LINQ Pocket Reference
by Joseph Albahari and Ben Albahari
Chapter 1 LINQ Pocket Reference LINQ, or Language Integrated Query, allows you to write structured type-safe queries over local object collections and remote data sources. It is a new feature of C# 3.0 and .NET Framework 3.5. LINQ lets you query any collection implementing IEnumerable, whether an array, list, XML DOM, or remote data source (such as a table in SQL Server). LINQ offers the benefits of both compile-time type checking and dynamic query composition. The core types that support LINQ are defined in the System. Linq and System.Linq.Expressions namespaces in the System. Core assembly. NOTE The examples in this book mirror the examples in Chap- ters 8–10 of C# 3.0 in a Nutshell (O’Reilly) and are pre- loaded into an interactive querying tool called LINQPad. You can download LINQPad from http://www.linqpad.net/. Getting Started The basic units of data in LINQ are sequences and elements. A sequence is any object
(2008)

