Understanding C#: ?? Operator

The ?? operator returns the left-hand operand if it is not null, or else it returns the right operand. int? i = null; int count = i ?? 0; The value that count is set to is 0. The ?? operator is short hand for: int? i = null; int count = i.HasValue ? i.Value : 0; Or int? i = null; int count = 0; if (i.HasValue) count = i.Value; The Understanding C# series at Coder Journal will be an on going project to help the readers to better understand the C# programming language that doesn’t get covered except at the more advanced levels.

May 11, 2007 · 1 min · 105 words · Nick Berardi

Creating a Vista like Search Box

Introduction In this post we are going to go over what it takes to create a control, and more specifically a Vista Search Box like control. Definition of Current Search Box The first thing to do when creating a new control for Windows Forms is determine all the states of the control. In our case the control states are rather simple: Inactive: Active: Text Entered: ...

March 26, 2007 · 6 min · 1095 words · Nick Berardi

Using Distributed Transactions in your Data Layer

Many developers use a pattern called ORM or Object Relation Mapping to generate data layers for their application. Many other developers choose to create their own data layers by hand. I have done both and I don’t have a preference of one over the other. With an ORM generator you have an easy to maintain data layer for your applications, when you create one by hand you have much more control of the data layer as far as object creation goes. ...

March 16, 2007 · 6 min · 1085 words · Nick Berardi

How To: Unit Test Hidden Classes

Unit testing is an important part of developing high quality software. Many of you are probably not familiar with the term Unit Testing. Wikipedia defines Unit Testing as In computer programming, unit testing is a procedure used to validate that individual units of source code are working properly. A unit is the smallest testable part of an application. In procedural programming a unit may be an individual program, function, procedure, web page, menu etc, while in object-oriented programming, the smallest unit is always a Class; which may be a base/super class, abstract class or derived/child class. Units are distinguished from modules in that modules are typically made up of units. ...

March 14, 2007 · 4 min · 716 words · Nick Berardi

Visual Studio 2005 Update for Windows Vista

I was reading Tim Sneath’s blog today and noticed his post on the release of a Visual Studio 2005 Update for Windows Vista was released. It is a recommenced update for anybody using both of these products. The final release of the VS 2005 update for Windows Vista is now available. This update fixes most of the issues that you may have faced with running Visual Studio 2005 on Windows Vista. Install Visual Studio 2005, the Service Pack 1 update, and then the Windows Vista update to get a fully-supported developer environment. ...

March 7, 2007 · 1 min · 108 words · Nick Berardi

Visual Studio Team Edition for Database Professionals Error Connecting in Vista

As you may all know I have Windows Vista Ultimate x64 and last post I talked about upgrading to SQL Server 2005 SP2. However while starting my first Database Project I encountered the following error. Microsoft Visual Studio An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified) OK It has basically taken me around 24 hours to finally find a solution. The solution was so simple, but yet totally undocumented on if you encounter this error do this. So I am hoping to at least correct that with this post for all the future Googler’s out there. ...

March 1, 2007 · 1 min · 201 words · Nick Berardi

Understand C#: Proper use IDisposable and using keyword

The System.IDisposable interface is a very useful interface to understand if you are concerned about performance in your application. Microsoft says the following about the IDisposable interface: The garbage collector automatically releases the memory allocated to a managed object when that object is no longer used, however, it is not possible to predict when garbage collection will occur. Furthermore, the garbage collector has no knowledge of unmanaged resources such as window handles, or open files and streams. ...

February 21, 2007 · 2 min · 371 words · Nick Berardi