Recently, I presented thirteen planned C# 6 features to my peers in one of our lunchtime ‘Brown Bag‘ talks. The format was informal, and included a ‘panel’ of judges formed of some of the more experienced developers on the team. After each feature was demonstrated, each member of the panel held aloft their score out of 10.

Some of the feedback on the features was quite interesting, enough so to present them in a series of blog posts.

There’s plenty of information already out there, a good selection contained in the following articles.

So what are the benefits of this? Well, we now have some short hand for declaring properties, which is nice, but the best thing about this is something I’ve alluded to in the comments:

Currently, if we want an immutable type, we cannot have an auto-property, as an auto-property must have a get and set accessor on it. Some will argue that private set makes a type immutable:

class UsingPrivateSet
{
//Can have an initializer on a read-only property - now we can have auto-properties on immutable types.
public string ImmutableProp3 { get; private set; }
}

This is true for simple types with no internal functionality that modifies state, however, more complex types classes may mutate the state of the object from private or even public methods. Inherently, use of private set does makes a class’ immutability dependent on other implementation factors.

Now we can have a get-only auto-property:

class GetterOnlyDemo
{
//Can have an initializer on a read-only property - now we can have auto-properties on immutable types.
public string ImmutableProp3 { get; } = "I can still be set";
}

And the compiler is smart enough to enforce the assignment of an auto-property, throwing an error if it is not set.

Panel score: This was presented in conjunction with Primary Constructors (next), so we’ll see the score there.

Overriding Default Encryption

By default, the functionality uses AesCryptoServiceProvider with a default encryption key and IV (Initialization Vector). At the very least, it’s advisable to override the Key and IV. There are three overridable items. in the in the following configuration:

Override Key and IV

Override Key, IV and Algorithm.

To override the default algorithm provider, we must specify one based upon SymmetricAlgorithm. If we do override the default (AesCryptoServiceProvider) we are required to stipulate a different Key and IV. This is because different algorithms require different key sizes. The .LegalKeySizes property of the CryptoServiceProvider instance tells you which key sizes are allowed.