[英]Can't Create MemoryStream using Custom File as Resource using C#
I am using C# and can't create a stream using a Resource. 我正在使用C#,并且无法使用Resource创建流。 The file is a custom file called 'test.usr' which contains a string.
该文件是名为“ test.usr”的自定义文件,其中包含一个字符串。 The build action for it is set to None (not sure if that matters).
它将其生成操作设置为“无”(不确定是否重要)。 The error is posted below.
错误在下面发布。 Does anyone know how I would correct this?
有人知道我会如何纠正吗?
Error: 'Looks up a localized string similar to ..... Can't convert from string to int.' 错误:“查找类似于.....的本地化字符串。无法从字符串转换为int。”
MemoryStream certStream = new MemoryStream(Properties.Resources.test);
Properties.Resources.test
is a string
. Properties.Resources.test
是一个string
。 MemoryStream does not have a constructor that accepts strings. MemoryStream没有接受字符串的构造函数。 It can accept an array of bytes though.
它可以接受字节数组。 So you can convert the
string
to an array of bytes: 因此,您可以将
string
转换为字节数组:
MemoryStream certStream = new MemoryStream(Encoding.UTF8.GetBytes(Properties.Resources.test));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.