Design Patterns: Adapter

Please see my other Design Pattern articles. Exposing class behavior from another class. Sometimes you might need to access and use functionality defined from one class from within your own class. To illustrate this pattern, I’ll begin with a simple class that contains one method I wish to invoke from within my other class –…

C#: String Operations

Please see my other C# articles. Performing common string operations. The .NET Framework is essential a huge repository of reusable classes that provide robust functionality organized by various namespaces. For example, the String namespace allows developers to easily and safely manipulate strings in a variety of ways. First, I’ll show I perform such basic string operations using…

C#: Type Inference

Please see my other C# articles. Writing flexible, elegant code for data storage. When writing business logic, it’s often difficult to determine at design-time what type an object will need to be or what type of data it will store. Thankfully, Microsoft has provided an elegant solution by allowing developers to write code that will store any…

C#: LINQ – Query

Please see my other LINQ articles. Performing a simple query. Using Microsoft’s new elegant syntax or subset of the .NET framework that looks like it might be replacing ADO.NET, I will illustrate how to perform a simple query. This new syntax is much less bulky than executing the same query using ADO.NET commands. First, I’ll begin by…

C#: Generics

Please see my other C# articles. Ensuring type-safety in objects. Whenever performing domain modeling, it’s critical to ensure code matches the real-world environment as much as possible. The chief method for doing so to utilize classes by which objects may be instantiated. However, having a collection of objects that are either the incorrect type or contain incorrect…

C#: 4.0 Anonymous Types

Please see my other C# articles. Simple, elegant data storage. One of the latest improvements to the .NET Framework in 4.0 is the ability to use object initializers to create simple data-storage objects without having to create a class or struct. Also, these anonymously-typed objects are created by the compiler so you still have strong-typing on your…

C#: ADO.NET Transactions

Please see my other C# articles. Ensuring data-concurrency. When a feature requires an atomic action, ADO.NET transactions easily ensure data concurrency while performing writes against the database.For example, let’s say two separate db writes are needed, each of which executes a stored procedure.Should errors occur, it’s essential that both writes are rolled-back before any changes are…