using System;
using System.IO;
using System.Text;
public class Movies
{
public string moviename { get; set; }
public int cast { get; set; }
public string[] castmember { get; set; }
public override string ToString()
{
return string.Format("Movie: {0} \nCast #: {1} \nCast Member: {3}",
moviename.ToString(),
cast,
castmember.ToString());
}
}
public class MovieData
{
public int NumberOfLines = 0;
public string UserInput;
public void ManageData()
{
string[] text = File.ReadAllLines("@File Path");
NumberOfLines = text.GetUpperBound(0);
Movies[] movies = new Movies[NumberOfLines];
int i = 0;
foreach (string line in text)
{
movies[i] = new Movies();
movies[i].moviename = Convert.ToString(line.Trim());
movies[i].cast = Convert.ToInt32(line.Trim());
int ii = movies[i].cast;
//Here I want to create a movies[i].castmember[ii] with ii being the length
}
I am trying to store data that is basically in line format, but there is a particular set of lines that would be more logical to store in an array.
How would I go about creating a movies[i].castmember array with length of ii (cast)?
I can notice some errors on your code.. for example you are converting the same
line.Trim()value intostringandInt32but this is not the question..I think you are asking how to create an array of
iielements..that’s it: