How do I access resources in a console application?

百般思念 提交于 2020-01-14 10:43:34

问题


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).

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


回答1:


Edited answer (after your edit):

You don't have resources.

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

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

Then use it:

string s = Resource1.String1;

Original answer:

Text = Properties.Resources.String1;

For example.

EDIT:

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;



回答2:


Your application does not appear to have any resources.




回答3:


You need add your file as Resource, open project's Properties, select Resources tab. Then Press Add Resource > Add Existing file. Select your file.

Make sure added resource file has Build Action = Resource



来源:https://stackoverflow.com/questions/16655520/how-do-i-access-resources-in-a-console-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!