0

I have several text files being read in to my program which are all being split into separate arrays, is there anyway to label the arrays so that the user can select one to view the contents. So if the user wanted to view dateData then is there anyway to label it?

static void Main(string[] args)
    {
        string[] dayData = File.ReadAllLines("Day.txt");
        string[] dateData = File.ReadAllLines("Date.txt");
        string[] sh1CloseData = File.ReadAllLines("SH1_Close.txt");
        string[] sh1DiffData = File.ReadAllLines("SH1_Diff.txt");
        string[] sh1OpenData = File.ReadAllLines("SH1_Open.txt");
        string[] sh1VolumeData = File.ReadAllLines("SH1_Volume.txt");
    }

Sorry, I'm very new to C#. Thanks.

1 Answers1

0

For "labeling", you can create a container class that holds the label (Label) and the data (Data):

public class FileData
{
    public string Label { get; set; }
    public string[] Data { get; set; }  
}

Usage:

var dayData = new FileData
{
    Label = "Day.txt",
    Data = File.ReadAllLines("Day.txt"),
};

You can then in turn store multiple FileData instances in a List<FileData>, if appropriate.

Alternatively, use a Dictionary<string, string[]> where the key is the "label":

var fileData = new Dictionary<string, string[]>();
fileData["Day.txt"] = File.ReadAllLines("Day.txt");

You also may want to reconsider using File.ReadAllLines(), File.ReadLines() may be a better choice.

How to sort string arrays has been asked before, use the search. See for example:

Community
  • 1
  • 1
CodeCaster
  • 147,647
  • 23
  • 218
  • 272