Hi everyone, I'm a beginner in C# and I haven't practiced programming since the days of the 8-bit computing. My project was intended to grab data from a list of filenames and store them in an array. The whole procedure was initiated after clicking on a windows form button.
I used a structure like this:
public struct dataDrugs
{ public StringBuilder active;
public StringBuilder brand;
public StringBuilder date;
public StringBuilder path;
}
I instantiated the structure like this:
dataDrugs newStruct = new dataDrugs();
The files that interested me were stored in an array.
And finally I used a foreach loop to extract data from the array and place them in newStruct.
Everything went as planned and after the button click my newStruct had 79 additions :
e.g. newStruct [78].active contained the value "amoxicillin"...
Each new addition had to be initialized in order to avoid runtime errors. I used the StringBuilder class like this:
newStruct[x].active= "whatever";
I did the same for all the member of newStruct.
The problem is that I cannot access what is stored in newStruct, outside the button_click event routine.

I will show you some of the code I used, to make it easier to understand (I hope!!!)
private void button1_Click (object sender, EventArgs e)
{
int x=0;
byte temp=0;
byte nameEnd=0;
StringBuilder library=new StringBuilder ();
StringBuilder tempStr=new StringBuilder ();
StringBuilder finalStr=new StringBuilder ();

FileStream myFileCreate=new FileStream (testFile, FileMode.Create);


string [] filesPDF=Directory.GetFiles (progDir, "*.pdf", SearchOption.AllDirectories);
string [] filesDOC=Directory.GetFiles (progDir, "*.doc", SearchOption.AllDirectories);
int lenghtPDF=filesPDF.Length;
int lengthDOC=filesDOC.Length;
dataDrugs [] drugSPC=new dataDrugs [lengthDOC+lenghtPDF];

foreach (string s in filesPDF)
{
tempStr.Append ("any");
library.Append ("any");
finalStr.Append ("any");
tempStr.Replace (tempStr.ToString (), string.Empty);
library.Replace (library.ToString (), string.Empty);
finalStr.Replace (finalStr.ToString (), string.Empty);
tempStr.Insert (0, s);
finalStr.Insert (0, s);
tempStr.Remove (0, 20);
nameEnd=(byte) tempStr.ToString ().IndexOf ("_");
drugSPC [x].brand=new StringBuilder ();// could not initialize inside struct
drugSPC [x].active=new StringBuilder ();
drugSPC [x].date=new StringBuilder ();
drugSPC [x].path=new StringBuilder ();


More code followed the above, but I guess that you get the picture.
I tried using a class instead of the structure but it made no difference.
I also tried to create a structure or class that contained arrays...
like this:
struct {
string [] active;
string [] brand;
string [] date;
string [] path;
}
Any suggestions?
Also could you comment on the difference between StringBuilder and simple strings in terms of memory efficiency and speed?