Set - 6

Question 1 :

Can I define a type that is an alias of another type (like typedef in C++)?

Answer :

Not exactly. You can create an alias within a single file with the "using" directive:

using System; using Integer = System.Int32; // alias

But you can't create a true alias, one that extends beyond the file in which it is declared. Refer to the C# spec for more info on the 'using' statement's scope.

Question 2 :

Is it possible to have different access modifiers on the get/set methods of a property?

Answer :

No. The access modifier on a property applies to both its get and set accessors. What you need to do if you want them to be different is make the property read-only (by only providing a get accessor) and create a private/internal set method that is separate from the property.

Question 3 :

Is it possible to have a static indexer in C#?

Answer :

No. Static indexers are not allowed in C#.

Question 4 :

Does C# support #define for defining global constants?

Answer :

No. If you want to get something that works like the following C code:

#define A 1
use the following C# code: class MyConstants{
	public const int A = 1;

Then you use MyConstants.A where you would otherwise use the A macro.
Using MyConstants.A has the same generated code as using the literal 1.

Question 5 :

Does C# support templates?

Answer :

No. However, there are plans for C# to support a type of template known as a generic. These generic types have similar syntax but are instantiated at run time as opposed to compile time. You can read more about them here.