|
Monday, 09 March 2009
|
|
HTML clipboard
- as an alias for a namespace
- allows you to use types of a particular namespace without the need for
qualifying the entire namespace
using [alias = ] class_or_namespace;
where:
alias(optional) - a user defined symbal that is representing a namespace.
class_or_namespace - is the namespace name that you wish to either use or
alias, or the class name that you wish to alias. Key Points:
Common use of using is to make life easier so you don't have to fully
quality ever statement.
Create a using directive to use the types in a namespace withough having to
specify that actual namespace.
A using directive does not give you access to any of the various
namespaces that might be nested in the namespace that you specified.
A user defined namespace is referring to any namespace you have created in yuor
code.
Example:
using System;
using CSF = CSharpFriends.BestResource.ForCSharp;
namespace CSharpFriends.BestResource
{
public class MyClass
{
public static void
DoNothing()
{
}
}
namespace ForCSharp
{
public class
MyNestedClass
{
public static void MyMessage()
{
System.Console.WriteLine("CSharpFriends!");
}
}
}
}
public class TestUsing
{
public static void Main()
{
CSF.MyNestedClass.MyMessage();
Console.ReadLine();
}
}
|