是否可以在 .resx 资源文件中定义字符串数组?
目前,我这样做:
Names -> "name1|name2|name3"
Resource.Names.Split('|');
是否可以将这些名称定义为资源文件中的数组,以便我不必每次都通过拆分进行解析?
也许像下面这样?
Names[] -> "name1"
Names[] -> "name2"
Names[] -> "name3"
Resource.Names; // is of type string[]
也许还有另一种更好的方法吗?
Currently, I do this:
Names -> "name1|name2|name3"
Resource.Names.Split('|');
Is it possible to define those names as an array in the resource file so that I don't have to parse by splitting every time?
Something like the following perhaps?
Names[] -> "name1"
Names[] -> "name2"
Names[] -> "name3"
Resource.Names; // is of type string[]
Is there perhaps another, better way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据 MSDN ResXResourceWriter页面可以使用那里提供的代码生成此类资源。字符串和数组都是可序列化类型,但是资源当然包含 Base64 编码的序列化数组表示,它不容易读写。但这是可能的,并且在添加生成的 resx 文件时可以正确检测类型。我使用以下代码进行测试:
也就是说,不,如果没有额外的自定义,就不可能以人类可读的形式在资源文件中定义字符串数组。
According to MSDN ResXResourceWriter page one can generate such resources using code provided there. Both string and array are serializable types, but of course resources contain Base64-encoded serialized array representation, which is not readable or writeable easily. But it is possible, and the type is detected correctly when adding generated resx file. I've used the following code to test:
That said, no, it is not possible to have string array defined inside resource file in human-readable form without additional customizations.
您可以使用应用程序设置来存储阵列。
转到您的应用程序属性,然后转到设置选项卡。您可以设置设置的名称,选择所需的类型、范围和值。
有关详细信息:http://msdn.microsoft。 com/en-us/library/aa730869%28VS.80%29.aspx
You can use the app settings to store your arrays.
Go to your apps properties then the settings tab. You can set the name of your setting, select what type you want, the scope and the values.
For more info: http://msdn.microsoft.com/en-us/library/aa730869%28VS.80%29.aspx