Thanks for your help.
It seems a good solution to use embedded resource file to manage this big arrays.
But there is another problem when getting this array back from resource file.
there is always a System.InvalidCastException for this line:
st[] a = (st[]) rm.GetObject("array 1",ci);
can anyone help?
It's ok to create a resource file using following code:
using System;
using System.Resources;
[Serializable]
struct st
{
public short t1,t2 ;
public st(short t1,short t2){
this.t1 = t1;
this.t2 = t2;
}
}
public class WriteResources {
public static void Main(string[] args) {
st[] a = {
new st(3,4),
new st(3,4),
new st(3,4),
new st(3,4),
new st(3,4),
new st(3,4)
};
// Creates a resource writer.
IResourceWriter writer = new ResourceWriter("myResources.resources");
// Adds resources to the resource writer.
writer.AddResource("String 1", "First String");
writer.AddResource("array 1", a);
writer.Generate();
// Writes the resources to the file or stream, and closes it.
writer.Close();
}
}
but failed when retrieve array back from the resource file,
using System;
using System.Resources;
using System.Collections;
using System.Globalization;
using System.Threading;
using System.Reflection;
[Serializable]
struct st
{
public short t1,t2 ;
public st(short t1,short t2){
this.t1 = t1;
this.t2 = t2;
}
}
class EnumerateResources
{
public static void Main()
{
// Create a resource manager to retrieve resources.
ResourceManager rm = new ResourceManager("myResources",
Assembly.GetExecutingAssembly());
CultureInfo ci = Thread.CurrentThread.CurrentCulture;
//It's ok to retrieve string
String str = rm.GetString("String 1", ci);
Console.WriteLine(str);
//THERE IS ALWAYS A System.InvalidCastException for this line:
st[] a = (st[]) rm.GetObject("array 1",ci);
Console.WriteLine(a[1].t1);
}
}