2
Answers

using directives

Maha

Maha

13y
1.1k
1
This program is given in following website:
http://msdn.microsoft.com/en-us/library/sf0df423(v=vs.80).aspx

Two questions are there

1) Even though nameSpace2 and using directives in nameSpace3 (using NameSpace1 and using NameSpace2;) are comment out program is still executing.

2) We have to use somevar.ToString() to access the ToString() method but here only "somevar" is used to access the ToString() method.

// cs_using_directive2.cs
// Using directive.
using System;
// Using alias for a class.
using AliasToMyClass = NameSpace1.MyClass;

namespace NameSpace1
{
public class MyClass
{
public override string ToString()
{
return "You are in NameSpace1.MyClass";
}
}
}

/*namespace NameSpace2
{
class MyClass
{
}
}*/

namespace NameSpace3
{
//using NameSpace1;
//using NameSpace2;

class MainClass
{
static void Main()
{
AliasToMyClass somevar = new AliasToMyClass();
Console.WriteLine(somevar);
}
}
}
Answers (2)