Shorthand notation for class member initialization

c#

Solution

If you are using a few particular types and want them shortened you can create an alias with a using statement, eg:

using ShortName = Abc.Xyz.ClassWithAVeryLongNameThatYouDontLikeTypingTooOften;

then within that file you could do something like:

class Abc
{
    ShortName xyz = new ShortName();
}

But as far as I know there's no `var` equivalent at the class level.

Problem

In a C# block, I can define and initialize a variable as follows: ``` var xyz = new Xyz(); ``` The type of `xyz` will be set accordingly. However, at the class level, I have to specify the type twice: ``` class Abc { Xyz xyz = new Xyz(); } ``` Is there a shorthand syntax that avoids typing out the type name twice? This isn't such a big deal with short types like `Xyz` but a shorter notation would help with LongTypeNames.

Original source

Related problems