什么是用C#错误codeS错误信息关联的最好方法?错误信息、错误、方法、codeS

由网友(傲似你祖宗°)分享简介:我有一个软件写在C#.NET与通过USB设备进行通信。当出现问题时该设备设置一个错误code这是由我的软件中的一个整数的形式读取。我要存储在我的C#程序,它与特定的固件错误codeS相关的错误信息。什么是存储这些最好的方法是什么?I have a piece of software written in C#.NET...

我有一个软件写在C#.NET与通过USB设备进行通信。当出现问题时该设备设置一个错误code这是由我的软件中的一个整数的形式读取。我要存储在我的C#程序,它与特定的固件错误codeS相关的错误信息。什么是存储这些最好的方法是什么?

I have a piece of software written in C#.NET that communicates with a device via USB. When a problem occurs the device sets an error code which is read by my software in the form of an integer. I want to store error messages in my C# program that correlate with the specific firmware error codes. What is the best way to store these?

有人告诉我,一个好的办法是使用资源文件。什么是使用一个资源文件的好处是什么?有没有更好的办法做到这一点?

I have been told that a good approach would be to use a Resource file. What are the benefits of using a resource file? Is there a better way to do it?

推荐答案

我会建议使用一个资源文件中。一个关键的好处是本地化(使用不同的语言)。即使你今天不想用多国语言,你给自己的灵活性,后来添加。另一个好处是简单的.NET / C#集成。

I would suggest using a Resource File as well. One key benefit is localization (using different languages). Even if you don't want to use multiple languages today, you give yourself the flexibility to add them later. Another benefit is the simple .NET/c# integration.

var key = "134"; //error code
var resourceFile = "someFileName.resx";
var filePath = "c:somepath";
ResourceManager resourceManager = ResourceManager
    .CreateFileBasedResourceManager(resourceFile, filePath, null);
resourceValue = resourceManager.GetString(key);

此外,资源文件是很容易去当谈到时间来更改消息。

Also, resource files are easy to get to when it comes time to change a message.

阅读全文

相关推荐

最新文章