"neverstill" <sk************@yahoo.com> wrote in message
news:ej**************@TK2MSFTNGP09.phx.gbl...
Hello-
I am a little confused about something. I have create a .cs file
that looks like this:
using System;
namespace MyApp.Types
{
using INT = System.Int32;
}
In my Main() function, even though I have added the using
directive : using Types; I get compiler errors with this line
of code: INT nrBones = 0;
So this doesn't make sense to me. How do you have custom
types all over your application if you can't do it like this?
What am I missing?
You haven't created a custom type, merely an alias [i.e. alternate or
shortened name] for an existing type. I'm assuming, also, that this is what
you actually wish to do - post again with additional information if it
isn't.
The reason the 'aliasing' didn't work was because you created it [I'm
assuming this, since you didn't show all your code] in one scope but
attempted to use it in another.
The following code snippets should helps clear this up. As they show, you
just need to ensure the alias created by the using directive is done so in
the correct scope / namespace.
I hope this helps.
Anthony Borla
// FILE: Example1.cs
using System;
using INT = System.Int32;
public class X
{
INT returnINT() { INT x = 5; return x; }
public static void Main(String[] args)
{
INT x = new X().returnINT();
Console.WriteLine(x);
}
}
// FILE: Example2.cs
using System;
namespace MyApp
{
using INT = System.Int32;
public class X
{
INT returnINT() { INT x = 5; return x; }
public static void Main(String[] args)
{
INT x = new X().returnINT();
Console.WriteLine(x);
}
}
}