如何访问控制台应用程序中的资源? [英] How do I access resources in a console application?

查看:112
本文介绍了如何访问控制台应用程序中的资源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在控制台应用程序中访问 .Properties.Resources ?这是使用解决方案附带的资源文件。

How do I gain access to .Properties.Resources in a console application? This is to use resource files attached to the solution.

这正是我所看到的:

Here's exactly what I can see:

第一个语法错误不是我关注的语法(只能将赋值,调用,递增,递减和新对象表达式用作语句)。

The first syntax error isn't the one I'm concerned with (Only assignment, call, increment, decrement, and new object expressions can be used as a statement).

我要解决的问题是第二个:名称'Properties'在当前上下文中不存在

The one that I'm trying to fix is the second: The name 'Properties' does not exist in the current context

推荐答案

编辑的答案(在您编辑后):

您没有拥有资源。

在解决方案资源管理器中右键单击测试->添加->新建项目->资源文件

Right-Click on 'test' in Solution Explorer -> Add -> New Item -> Resources File

然后双击创建的文件(例如Resource1.resx),然后从那里获取。

Then double-click on the created file (e.g. Resource1.resx), and take it from there.

然后使用它:

string s = Resource1.String1;

原始答案

Text = Properties.Resources.String1;

例如。

编辑:

解决方案资源管理器属性旁边的小三角形>,然后对资源执行相同的操作。然后双击 Resources.Designer.cs

Click on the little triangle next to Properties in Solution Explorer, then do the same for Resources. Then double click Resources.Designer.cs.

然后在此处复制命名空间:

Then copy the namespace there like this:

TheNameSpace.Properties.Resources.String1;

这篇关于如何访问控制台应用程序中的资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆