Best place to store saved messages

柔情痞子 提交于 2021-01-28 18:55:24

问题


I am currently creating a console applications that only accepts some commands defined by me. The thing is I'm storing a lot of error and notification messages on a static class I created called Messages and then just calling them like Messages.ErrorMessage.... ErrorMessage is just a static string that contains w/e I want printed on the console. What I wanted to ask is if that's a good way of implementing such behavior or should I instead change where I'm keeping all of this Messages?

Thanks for your help!


回答1:


I guess for your need you can use Resource file instead of static class.

as documented on official site

Visual C# applications often include data that is not source code. Such data is referred to as a project resource and it can include binary data, text files, audio or video files, string tables, icons, images, XML files, or any other type of data that your application requires. Project resource data is stored in XML format in the .resx file (named Resources.resx by default) which can be opened in Solution Explorer.

For more information :-

http://msdn.microsoft.com/en-us/library/7k989cfy(v=VS.90).aspx




回答2:


As suggested by others, storing them in resource files is the recommended way to deal with such resources, particularly if you'll need to deal with internationalization. then you can load a different resource file from a satellite assembly at run time with the correct information.

You will notice a slight performance hit as the strings will be looked up in a resource dictionary, but usually that is negligible.



来源:https://stackoverflow.com/questions/24117580/best-place-to-store-saved-messages

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