什么是用C#错误codeS错误信息关联的最好方法? [英] What is the best way to associate error messages with error codes in C#?

查看:144
本文介绍了什么是用C#错误codeS错误信息关联的最好方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个软件写在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:\some\path\";
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.

这篇关于什么是用C#错误codeS错误信息关联的最好方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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