cotj73
asked on
Use of a multidemensional Array
I am using c# to write a program,
i have the data that i need to use in a text file, that is saves as a comma seperated list, with multiple lines
Ex
s[0] = {a,b,c}
s[1] = {d,e,f}
s[2] = {g,h,i}
I am looking for how to pull in this data as a multidemensional array, or whatever would be the easiest thing to use.
any suggestions?
i have the data that i need to use in a text file, that is saves as a comma seperated list, with multiple lines
Ex
s[0] = {a,b,c}
s[1] = {d,e,f}
s[2] = {g,h,i}
I am looking for how to pull in this data as a multidemensional array, or whatever would be the easiest thing to use.
any suggestions?
ASKER
the only problem that i forsee in this approach is that i have to read about 325 lines, and each line holds about 40 different values.
here is an example of a line
-.2,-.2,19785,0,T 04/17/2009,13:35:28.953000 UTC,first,middle,last,1946 -11-11,Gen der,OD,,ZE RNIKE,SCAL E: 2.56245844477293E-03,28,0, 7.26319504 749052E-04 ,-1.284357 03005351E- 04,-4.7073 6639230834 E-04,-2.11 6961947416 56E-04,-6. 9418817015 8255E-06,1 .217603273 35195E-05, -1.1647118 9175351E-0 4,1.892881 053328E-04 ,2.4339408 9421797E-0 5,-4.27588 262279435E -06,3.9642 8568852939 E-05,1.214 1645842366 1E-05,-5.0 7598197431 613E-06,2. 4283558166 9891E-05,1 .846781277 20032E-05, -1.6793619 674676E-05 ,-5.208980 49006682E- 06,-1.7689 2518358479 E-05,-7.00 4854512636 67E-06,1.3 8926890110 059E-05,-1 .610876506 49244E-05, 1.32222083 318142E-05 ,2.2804883 2601142E-0 5,4.929095 74194228E- 05,-3.9719 165605381E -05,-3.308 7430580673 5E-05,4.36 6588250069 91E-05,-1, 0,-1,-5.05 9060532721 66E-03,-3. 5132039378 1458E-03,6 .186993689 03292E-04, 4.70280112 56734E-04, 1003597,
here is an example of a line
-.2,-.2,19785,0,T 04/17/2009,13:35:28.953000
Won't be any problem with it just make 40 properties in the class. Another benefit that you might like since it looks like measurements your working with is with this approach you can easily sort based on column as well.
ASKER
would it be possible in this class to use a for loop in the declaration,
many of the values of the text are
z00
z10
z11
z20
z21
z22
...
z65
z66
i have an algorythm to do this
for (int i = 0; i <= iFValue; i++)
{
for (int j = 0; j <= i; j++)
{
dgvSlectedPatient.Columns. Add("cZ" + Convert.ToString(i) + Convert.ToString(j), "Z" + Convert.ToString(i) + Convert.ToString(j));
}
}
i am using this elseware. would this work if i used it instead of adding colums have it sequence through
or does that not work for classes
many of the values of the text are
z00
z10
z11
z20
z21
z22
...
z65
z66
i have an algorythm to do this
for (int i = 0; i <= iFValue; i++)
{
for (int j = 0; j <= i; j++)
{
dgvSlectedPatient.Columns.
}
}
i am using this elseware. would this work if i used it instead of adding colums have it sequence through
or does that not work for classes
ASKER
sorry here is a better look
for (int i = 0; i <= 6; i++)
{
for (int j = 0; j <= i; j++)
{
"cZ" + Convert.ToString(i) + Convert.ToString(j);
}
}
and will this method work of all of the lines that i have to read
for (int i = 0; i <= 6; i++)
{
for (int j = 0; j <= i; j++)
{
"cZ" + Convert.ToString(i) + Convert.ToString(j);
}
}
and will this method work of all of the lines that i have to read
Another option you have is creating an array in the class just for the cZ items and using the properties for the rest. Like this:
List<person> Persons = new List<person>();
person newPerson = new person();
for (int i = 0; i <= 6; i++)
{
for (int j = 0; j <= i; j++)
{
newPerson.cz[int.Parse(Convert.ToString(i) + Convert.ToString(j))] = "Set the value for each field here";
}
}
Persons.Add(newPerson);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Great Help, Thank You
For example if you had an CSV with 3 fields called id, firstname, lastname make an class like this:
class person
{
public int id { get; set; }
public string firstname { get; set; }
public string lastname { get; set; }
}
Then create an List<T> of the collection.
List<person> Persons = new List<person>();
The go through each line of the CSV and add it to the List
Persons.Add(new person() { id = csv[0], firstname = csv[1], lastname = csv[2] });
Whats nice about this approach is you can use a number of different approaches for accessing the data like foreach or LINQ. For example if you wanted to use LINQ against it you could type:
var results = from p in Persons
where p.id == 5
select p;
or an foreach
foreach(var currentPerson in Persons)
{
MessageBox.Show(currentPer
}