3

I was just checking a code snippet. At the top of his class this guy had his namespaces like:

using System;
using System.Text;

but then he did something I've never seen before:

using input = System.Char;

Later on he declares a variable:

public input? data;

So I was wondering, why doesn't he just make a char variable? instead of saving System.char into input and then using input as type.

Note, it was a fairly old code snippet.

1
  • Don't try to understand what's in the obscure mind of someone's else code, it can hurt your mental health :-) Commented Aug 19, 2013 at 13:58

3 Answers 3

3

So I was wondering, why doesn't he just make a char variable?

You'd have to ask the original author. But we can guess, it makes it possible to later change to

using input = System.Int32;

and then

public input? data;

Becomes something different but it keeps working. It would be possible to keep most/all of the code to continue working for a different type.

So it gives a Single Point of Definition (SPoD) for the Type of input.

But having said that, it is a rare practice and completely superseded by generics (List<T>).

Sign up to request clarification or add additional context in comments.

Comments

2

This is called an alias for a namespace or a type. It is quite common to abbreviate long namespaces or types to shorter names.

See MSDN

Comments

0

It's simply an alias. It was likely used so that if the input type needed to change in the future, it could be changed quickly and easily in one place, rather than having to find and replace all instances of it throughout the file.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.