Archive for October, 2008

When you learn a new language you tend to settle into using it in a particular way. So if you missed a little known feature it is unlikely you will suddenly find it unless someone points it out. Here are 5 of my favorite C# features that you might not already be using.

1 – ?? Operator
The ?? operator is called the null-coalescing operator and is used to define a default value for a nullable value types as well as reference types. It returns the left-hand operand if it is not null; otherwise it returns the right operand. So instead of using code like this…

if (reference == null)
   return _defaultInstance;
else
   return reference;

You can just write the following statement instead…

return reference ?? _defaultInstance;

Much cleaner and it even works for nullable value types.

 

2 - DebuggerStepThrough
This attribute can be added to a method or property accessor and used to speed up debugging. When debugging and using step-into the debugger will step past the method with this attribute. This is really useful in preventing you stepping in and out of the many one liners in the code. To apply do this…

public string Name 
{
   [DebuggerStepThrough]
   get { return _name; }
    
   [DebuggerStepThrough]
   set { _name = value; }
}
 

3 – Automatic Properties
Sick and tired of adding get/set code for simple properties? This is no longer a problem with the automatic properties added in C# 3.0. Instead of this…

private string _name;
public string Name
{
   get { return _name; }
   set { _name = value; }
}

…just do this…

public string Name { get; set; }
 

4 - Object Initializers

Also introduced in C# 3.0 are object initializers. This allows you to set property values inside the new statement. Without this you either create additional overloaded constructor with the possible set of initial values or you write the long hand like this…

Employee emp = new Employee();
emp.Name = "John Smith";
emp.Age = 10;

…but this is clearer…

Employee emp = new Employee {Name="John Smith", Age=10}

5 - Constant flags

Want to specify a float instead of a double for a constant? Most people know the ‘f’ modifier after a constant number informs the compiler to make it a single float value. But did you know the full list of others flags?

100m  (decimal)
100f  (float)
100d  (double)
100u  (uint)
100l  (long)
100ul (ulong)

Let me know if I have missed one you really like.

Am I the only one that is actually getting some enjoyment from watching the global financial crises?

I know I shouldn’t find it quite so fascinating but for some reason I do. Like watching a beautiful tornado just before it smacks you in the face. Just because you know it’s going to hurt doesn’t stop it looking amazing on the way in.

I’m sure I won’t find it so fascinating as I stand inline at the soup kitchen. But watching the stock market and governments panic is not an everyday sight. If the financial world is sinking like the Titanic then I might as well stand of deck and enjoy the view.

Actually I blame the The Daily Show and the The Colbert Report, they could make the end of days sound funny.

If you’re building an application using the Krypton controls then you need to add a final polish by using a set of professional icons. Otherwise all that hard work creating a nice looking app is going to waste.

To help make this process as easy as possible you can now buy a pack of 265 icons. As an introductory offer the price is just $79 during this month. Each icon has…

Three different sizes

Three different states

 

6 different file formats

- PNG, GIF
- ICO, PSD
- BMP (24bit & 32bit).

You can see a preview of all the icons here.

If you’re looking for Kryptonized controls for date and time entry then take a look at VisualHint.com that have recently added KryptonPalette support. Also offered are a property grid control and other input controls that might interest you.

As many of you will already know I am going to be adding some Kryptonized date and calendar controls to the Toolkit for the next major release. I am doubtful that the Toolkit versions will have the same level of customization as the commercial version from VisualHint.

Update: Here is a link you should check out.

This maintenance release has several major bug fixes and a bonus control added to the Toolkit.

Download Link for 3.0.6

Major Bug Fixes
- Locking/Unlocking computer causes text to disappear.
- Text not drawing at all for some Visual Studio projects.
- ComboBox drop down not working on some computers.
- Cannot edit Image properties with KryptonContextMenu.
- Design time change of Ribbon.MinimizedMode crashes.
- Removing all Ribbon tabs still draws last tab shown.

Feature Changes
- KryptonDomainUpDown added to the Toolkit.
- KryptonBreadCrumb now has overflow button feature.

If you have a valid subscription to one of the commercial products the you should already have received an email notification with download details. You do not need new serial keys, existing 3.0 keys will work just fine. Also remember to uninstall your current version before installing the new one.