别名 [英] Alias names
问题描述
i尝试定义别名,然后在另一个文件中使用它:
// ----- -----
//文件:a.cs
使用系统;
使用MyAlias = MyNamespace.MyClass;
命名空间MyNamespace {
公共类MyClass {
public MyClass(){。 。 。 }
}
}
// ----------
//文件:b.cs
命名空间MyNamespace {
公共类OtherClass {
public MyAlias m_theClass;
public OtherClass(){。 。 。 }
}
}
编译器说:找不到类型或命名空间名称''MyAlias'' ......
我错过了什么吗?我可以在a.cs中使用MyAlias就好了。
thx
Kimmo Laine
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
推荐答案
不幸的是,别名只会在定义
的物理文件中有效。
因为我们没有像
#include" a.cs"
没有办法解决这个问题。
您必须将using语句添加到任何文件中你想用
别名。
-
问候,
DennisJDMyrén
Oslo Kodebureau
" Kimmo Laine" < reply.to@newsgroup>在消息中写道
新闻:%2 ****************** @ TK2MSFTNGP09.phx.gbl ...
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...
我尝试定义别名,然后在另一个文件中使用它:
// ----------
/ / file:a.cs
使用System;
使用MyAlias = MyNamespace.MyClass;
命名空间MyNamespace {
公共类MyClass {
public MyClass(){。 。 。 }
}
// ----------
//文件:b.cs
namespace MyNamespace {
public class OtherClass {
public MyAlias m_theClass;
public OtherClass(){。 。 。 }
}
编译器说:类型或名称空间名称''MyAlias''无法找到......"
我错过了什么吗?我可以在a.cs中使用MyAlias就好了。
Kimmo Laine
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
>
嗨Dennis,
Kimmo
"DennisMyrén" <德**** @ oslokb.no>在留言中写道
news:_4 ******************** @ news2.e.nsc.no ...
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...
因为我们没有像
#include" a.cs"
没有办法解决这个问题。
你必须将using语句添加到你想要使用的任何文件中。
-
问候,
DennisJDMyrén
Oslo Kodebureau
Kimmo Laine < reply.to@newsgroup>在消息中写道
新闻:%2 ****************** @ TK2MSFTNGP09.phx.gbl ...
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...
我尝试定义别名,然后在另一个文件中使用它:
// ----------
//文件:a .cs
使用系统;
使用MyAlias = MyNamespace.MyClass;
命名空间MyNamespace {
公共类MyClass {
public MyClass( ){。 。 。 }
}
// ----------
//文件:b.cs
namespace MyNamespace {
public class OtherClass {
public MyAlias m_theClass;
public OtherClass(){。 。 。 }
}
编译器说:类型或名称空间名称''MyAlias''无法找到......"
我错过了什么吗?我可以在a.cs中使用MyAlias就好了。
Kimmo Laine
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
>
Kimmo,
C#中定义的基本类型由编译器知道
因此在一个特殊的方式。
-
问候,
DennisJDMyrén
奥斯陆Kodebureau
Kimmo Laine < reply.to@newsgroup>写在消息
新闻:uZ ************** @ TK2MSFTNGP14.phx.gbl ...
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...
嗨丹尼斯,
System.Int32别名" int"解决这个限制?
Kimmo
"DennisMyrén" <德**** @ oslokb.no>在消息中写道
新闻:_4 ******************** @ news2.e.nsc.no ...
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...
不幸的是,别名只会在定义它的物理文件中有效。
因为我们没有像
> #include" a.cs那样的东西
没有办法围绕这个。
你必须将using语句添加到你想要使用该别名的任何文件中。
-
问候,
DennisJDMyrén
Oslo Kodebureau
Kimmo Laine < reply.to@newsgroup>在消息中写道
新闻:%2 ****************** @ TK2MSFTNGP09.phx.gbl ...
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...
我尝试定义别名,然后在另一个文件中使用它:
// ----------
//文件:a .cs
使用系统;
使用MyAlias = MyNamespace.MyClass;
命名空间MyNamespace {
公共类MyClass {
public MyClass( ){。 。 。 }
}
// ----------
//文件:b.cs
namespace MyNamespace {
public class OtherClass {
public MyAlias m_theClass;
public OtherClass(){。 。 。 }
}
编译器说:类型或名称空间名称''MyAlias''无法找到......"
我错过了什么吗?我可以在a.cs中使用MyAlias就好了。
Kimmo Laine
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
>
这篇关于别名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!