C#替代到Visual Basic .NET命名空间我空间、Visual、Basic、NET

2023-09-06 16:29:57 作者:残缺的美丽

我是一个VB.NET的程序员,但我新的C#,现在我正与C#项目,使用本地资源文件(的.resx)。

I'm a VB.NET programmer, but I'm new to C# and now I'm working with C# project which uses local resource files (.resx).

使用VB.NET我可以通过访问在资源文件中的变量我的.resources< 。LocalResourceFile>< MyVariable的>。但在C#中我找不到我命名空间的任何选择,但我仍然可以访问的资源,如果我取代我命名空间以< MyProjectNamespace>。

Using VB.NET I can access to variables in resource file via My.Resources.< LocalResourceFile >.< MyVariable > . But in C# I can't find any alternatives for My namespace, but I still can access to resource if I replace My namespace with < MyProjectNamespace >.

也许有访问我的本地资源的任何其他方式?

Maybe there are any other way to access my local resources?

推荐答案

如果你绝对的必须的使用命名空间的等价物,有实际上是在C#这样的事情。这是 Microsoft.VisualBasic.Devices.MyServices 命名空间。要使用,必须添加一个引用Microsoft.VisualBasic.dll中添加使用Microsoft.VisualBasic.Devices; 到code文件。对于这条路线,在这里看到: http://msdn.microsoft.com/en-美国/库/ ms173136.aspx

If you absolutely must use the equivalent of the My namespace, there is actually such a thing in C#. It is the Microsoft.VisualBasic.Devices.MyServices namespace. To use that, you must add a reference to Microsoft.VisualBasic.dll and add using Microsoft.VisualBasic.Devices; to your code file. For this route, see here: http://msdn.microsoft.com/en-us/library/ms173136.aspx

我不会,但是建议这样做。相反,访问资源,您只需使用 MyNamespace.Properties.Resources 是这样的:

I would not, however recommend doing that. Instead, to access resources, you simply use MyNamespace.Properties.Resources like this:

namespace SomeNamespace
{
...
    var myFile = SomeNamespace.Properties.Resources.MyFile;
...
}