0

When using the XmlAttributeAttribute class in C#, I'm told that the class name XmlAttributeAttribute can be simplified to XmlAttribute.

I'm unsure how this works exactly. How am I permitted to refer to a class by a shortened name? How does C# know that this is valid? I can not see this referenced in any documentation.

Also, does this rule apply to other classes/components within the C# environment?

1 Answers1

2

I can not see this referenced in any documentation.

Really? did you see the MSDN documentation for XmlAttributeAttribute Class. It clearly says:

Note: You can use the word XmlAttribute in your code instead of the longer XmlAttributeAttribute.

To address your Second question

Also, does this rule apply to other classes/components within the C# environment?

Yes it does, in whichever situation compiler can infer it; you don't need to be explicit. For example, if you have defined a generic function like

public void method<T>(T arg, string arg1)
{
  // some code
}

You can just call the function saying below cause it can infer the type from the first parameter which is of type T

string str1 = "test";
method(str1, null);

Instead of being explicit and calling like

method<string>(str1, null);

You will get the same kind of info message name can be simplified

Rahul
  • 76,197
  • 13
  • 71
  • 125