473,396 Members | 1,966 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Alias names

Hi,

i try to define alias and then use it in another file like this:

// ----------
// file: a.cs
using System;

using MyAlias = MyNamespace.MyClass;

namespace MyNamespace {
public class MyClass {
public MyClass() { . . . }
}
}

// ----------
// file: b.cs

namespace MyNamespace {
public class OtherClass {
public MyAlias m_theClass;
public OtherClass() { . . . }
}
}

Compiler says: "The type or namespace name 'MyAlias' could not be found..."
Am i missing something? I can use the MyAlias in a.cs just fine.

thx

Kimmo Laine
Nov 16 '05 #1
10 2367
The alias will, unfortunately, be effective only in the physichal file where
it was defined.
Since we have nothing like
#include "a.cs"
there is no way around this.
You will have to add the using statement to any file where you want to use
that alias.

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Kimmo Laine" <reply.to@newsgroup> wrote in message
news:%2******************@TK2MSFTNGP09.phx.gbl...
Hi,

i try to define alias and then use it in another file like this:

// ----------
// file: a.cs
using System;

using MyAlias = MyNamespace.MyClass;

namespace MyNamespace {
public class MyClass {
public MyClass() { . . . }
}
}

// ----------
// file: b.cs

namespace MyNamespace {
public class OtherClass {
public MyAlias m_theClass;
public OtherClass() { . . . }
}
}

Compiler says: "The type or namespace name 'MyAlias' could not be
found..."
Am i missing something? I can use the MyAlias in a.cs just fine.

thx

Kimmo Laine

Nov 16 '05 #2
Hi Dennis,

how does the System.Int32 alias "int" work around this limitation?

Kimmo
"Dennis Myrén" <de****@oslokb.no> wrote in message
news:_4********************@news2.e.nsc.no...
The alias will, unfortunately, be effective only in the physichal file
where it was defined.
Since we have nothing like
#include "a.cs"
there is no way around this.
You will have to add the using statement to any file where you want to use
that alias.

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Kimmo Laine" <reply.to@newsgroup> wrote in message
news:%2******************@TK2MSFTNGP09.phx.gbl...
Hi,

i try to define alias and then use it in another file like this:

// ----------
// file: a.cs
using System;

using MyAlias = MyNamespace.MyClass;

namespace MyNamespace {
public class MyClass {
public MyClass() { . . . }
}
}

// ----------
// file: b.cs

namespace MyNamespace {
public class OtherClass {
public MyAlias m_theClass;
public OtherClass() { . . . }
}
}

Compiler says: "The type or namespace name 'MyAlias' could not be
found..."
Am i missing something? I can use the MyAlias in a.cs just fine.

thx

Kimmo Laine


Nov 16 '05 #3
Kimmo,

The primitive types defined in C# are known by the compiler
and is therefore treated in a special way.
--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Kimmo Laine" <reply.to@newsgroup> wrote in message
news:uZ**************@TK2MSFTNGP14.phx.gbl...
Hi Dennis,

how does the System.Int32 alias "int" work around this limitation?

Kimmo
"Dennis Myrén" <de****@oslokb.no> wrote in message
news:_4********************@news2.e.nsc.no...
The alias will, unfortunately, be effective only in the physichal file
where it was defined.
Since we have nothing like
#include "a.cs"
there is no way around this.
You will have to add the using statement to any file where you want to
use that alias.

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Kimmo Laine" <reply.to@newsgroup> wrote in message
news:%2******************@TK2MSFTNGP09.phx.gbl...
Hi,

i try to define alias and then use it in another file like this:

// ----------
// file: a.cs
using System;

using MyAlias = MyNamespace.MyClass;

namespace MyNamespace {
public class MyClass {
public MyClass() { . . . }
}
}

// ----------
// file: b.cs

namespace MyNamespace {
public class OtherClass {
public MyAlias m_theClass;
public OtherClass() { . . . }
}
}

Compiler says: "The type or namespace name 'MyAlias' could not be
found..."
Am i missing something? I can use the MyAlias in a.cs just fine.

thx

Kimmo Laine



Nov 16 '05 #4
Hi,

AFAIK "using alias" works with "namespace" only.
So you should not use it for "class".

Marcin
Hi,

i try to define alias and then use it in another file like this:

// ----------
// file: a.cs
using System;

using MyAlias = MyNamespace.MyClass;

namespace MyNamespace {
public class MyClass {
public MyClass() { . . . }
}
}

// ----------
// file: b.cs

namespace MyNamespace {
public class OtherClass {
public MyAlias m_theClass;
public OtherClass() { . . . }
}
}

Compiler says: "The type or namespace name 'MyAlias' could not be found..."
Am i missing something? I can use the MyAlias in a.cs just fine.

thx

Kimmo Laine

Nov 16 '05 #5
Although using statements certainly is more frequently used to import
namespaces,
they may also be used to create aliases for types.

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Marcin Grzêbski" <mg*******@taxussi.no.com.spam.pl> wrote in message
news:co**********@atlantis.news.tpi.pl...
Hi,

AFAIK "using alias" works with "namespace" only.
So you should not use it for "class".

Marcin
Hi,

i try to define alias and then use it in another file like this:

// ----------
// file: a.cs
using System;

using MyAlias = MyNamespace.MyClass;

namespace MyNamespace {
public class MyClass {
public MyClass() { . . . }
}
}

// ----------
// file: b.cs

namespace MyNamespace {
public class OtherClass {
public MyAlias m_theClass;
public OtherClass() { . . . }
}
}

Compiler says: "The type or namespace name 'MyAlias' could not be
found..."
Am i missing something? I can use the MyAlias in a.cs just fine.

thx

Kimmo Laine


Nov 16 '05 #6
Marcin Grzebski <mg*******@taxussi.no.com.spam.pl> wrote:
AFAIK "using alias" works with "namespace" only.
So you should not use it for "class".


Nope, that's not true. For instance:

using FooBar = System.Console;

public class Test
{
static void Main()
{
FooBar.WriteLine ("Hello");
}
}

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #7
Hi Jon and Dennis,

Upsss....
My ignorance was a step before .NET docs :-(

THANKS!
Marcin
Nov 16 '05 #8
Hi,

Some time ago i tried something like this:

using System.Console;

public class Test
{
static void Main()
{
Console.WriteLine ("Hello");
}
}

....but it does not work, without alias (now i can see):

using Console=System.Console;

JAVA have support for class (and packages) "import", and i miss
this feature in C#.

Marcin
Nov 16 '05 #9
VB.NET has this "feature" as well.

I wouldn't implement such a thing in my code. For instance:

using System.Console;
..
..
..
WriteLine("Hello green world!");
..
..

Now how would instantly know, when reviewing the code, that i mean
Console.WriteLine and not Debug.WriteLine??

Maybe for console and debug this is fine, but for our domain objects?
*shrug*

--
Patrik Löwendahl [C# MVP]
cshrp.net - 'Elegant code by witty programmers'
cornerstone.se 'IT Training for professionals'

Marcin Grzębski wrote:
Hi,

Some time ago i tried something like this:

using System.Console;

public class Test
{
static void Main()
{
Console.WriteLine ("Hello");
}
}

...but it does not work, without alias (now i can see):

using Console=System.Console;

JAVA have support for class (and packages) "import", and i miss
this feature in C#.

Marcin

Nov 16 '05 #10
Hi Patrik,
I wouldn't implement such a thing in my code. For instance:

using System.Console;
.
.
.
WriteLine("Hello green world!");

Now how would instantly know, when reviewing the code, that i mean
Console.WriteLine and not Debug.WriteLine??

Maybe for console and debug this is fine, but for our domain objects?
*shrug*
In JAVA class "import" (C# using) means that this class is directly
available, like in the code below:
using System.Console; // its forbiden i C#, of course

public class Test
{
static void Main()
{
Console.WriteLine ("Hello");
}
}
So, you cannot access directly to its "static" methods (fields,...)
WriteLine("Hello green world!");


but you can use it name without its namespaces (packages).
Console.WriteLine ("Hello");


Only difference in JAVA's "import" is that all classes from within
package are declared by "*" e.g.:

import java.util.*;

means that you can access all classes from package "java.util"
but:

import java.util.ArrayList;

means that only class "ArrayList" is available to use in your code.

So, its a most common way (in Java coding) to imports all needed
classes, besides imports its packages.

As i wrote before i can use alias same with class name in C#,
but it is the option only, e.g.:

using ArrayList=System.Collection.ArrayList;

Regards
Marcin
Nov 16 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Bill Kratzer | last post by:
Hi... I am currently working on a Java-based product that is backed by PostgreSQL (among other databases). I have noticed that PostgreSQL appears to truncate column alias names after 31...
3
by: Andrew | last post by:
With command-line interface ( 3.23.37, UNIX Socket ) all is well with column aliasing. However, column aliases disappear in Excel, over ODBC, when there are multiple (joined) tables in the query. ...
0
by: Steve | last post by:
WIN2000 sp4, SQL2000 sp3 I created an alias on the local server for the SQL 2000 server installed there, I can view and modify most sql server properties using this alias, but when I attempt to...
3
by: Ben | last post by:
Hi, Is there any way to set up an alias for a database within an SQL script? What I'm trying to acheive is... instead of having - <DatabaseName>.dbo.table, <DatabaseName2>.dbo.table, etc. -...
14
by: John | last post by:
Hi all, I am doing the change from having worked in Oracle for a long time to MS SQL server and am frustrated with a couple of simple SQL stmt's. Or at least they have always been easy. The...
3
by: A.V.C. | last post by:
Hello, I found members of this group very helpful for my last queries. Have one problem with CASE. I can use the column name alias in Order By Clause but unable to use it in WHERE CLAUSE. PLS...
5
by: Santiago Ordax Solivellas | last post by:
Hi. We have almost all our tables defined on library lib1 and some on lib2. We have alias defined on lib1 to access tables on lib2 so there is no need to qualify library name. Alias for tables on...
5
by: Jon Shemitz | last post by:
I'm playing with 2.0's extern alias declarations and the :: operator. If I have an extern alias My; and the My namespace contains a TypeName, I can refer to My::TypeName .... or to...
21
by: Peter Olcott | last post by:
I got the previous alias to std::vector working, and found that it takes up the space of a pointer. I want to find a way to do an alias to a std::vector that does not take up any space. Is there...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.