Archive for Programming

Nullable Types Summary

Nullable types (supported from .NET 2.0) are instances of the System.Nullable<T> struct. A nullable type can represent the correct range of values for its underlying value type, plus an additional null value.

Nullable types are declared in one of two ways:

  • System.Nullable<T> variable


  • T? variable

The ability to assign null to numeric and Boolean types is especially useful when you are dealing with databases and other data types that contain elements that may not be assigned a value. For example, a Boolean field in a database can store the values true or false, or it may be undefined. Yes, the nullable type modifier enables C# to create value-type variables that indicate an undefined value.

T is the underlying type of the nullable type. T can be any value type including struct; it cannot be a reference type. Reference types already support the null value.

Read more

[C#] Enumeration Types Summary

An enumeration type (also named an enumeration or an enum) provides an efficient way to define a set of named integral constants that may be assigned to a variable.

Usually it is best to define an enum directly within a namespace so that all classes in the namespace can access it with equal convenience. However, an enum can also be nested within a class or struct.

Every enumeration type has an underlying type (byte, sbyte, short, ushort, int, uint, long, or ulong), which can be any integral type except char. The default underlying type of enumeration elements is int. To declare an enum of another integral type, such as byte, use a colon after the identifier followed by the type.

The default value of an enum E is the value produced by the expression (E)0, and the value of each successive enumerator is increased by 1 if it’s not explicitly assigned. When you create an enum, select the most logical default value and give it a value of zero, or you can consider creating a None enumerated constant. That will cause all enums to have that default value if they are not explicitly assigned a value when they are created.

When assigning values to the elements in the enumerator list, you can also use coputed values, for example:

enum MachineState
PowerOff = 0,
Running = 5,
Sleeping = 10,
Hibernating = Sleeping + 5

Read more

[VS] Solution to “Changes to 64-bit applications are not allowed”

One of the most popular features in the Visual Studio debugger is the ability to edit code during a debug session and have the changes apply without having to stop the debugger, recompile the application and then run the application to verify the changes. This feature is affectionately known as “Edit and Continue” or “E&C” for short.

Unfortunately, Edit and Continue isn’t supported on 64-bit. In fact, if you try to use Edit & Continue when debugging a 64-bit application, you get the following error message: “Changes to 64-bit applications are not allowed”, as shown below.

Read more

x64: Problem “The ‘Microsoft.Jet.OLEDB.4.0′ provider is not registered on the local machine.” and Solution

There are times when the coexistence of x64 and x86 code on the same machine can cause all sorts of seemingly strange issues.

Recently I was getting the following error:

The “Microsoft.Jet.OLEDB.4.0” provider is not registed on the local machine.

I think the error is generally due to either of two things:

  • you don’t have Office 2007 / 2010 Jet driver installed on your Windows;
  • or you are running a x86 application in a default x86 enviroment.

Read more