I enjoy trying new ways (to me) of doing getting my code to be more efficient. I'm currently working on a database system (front end to an access file with added bits) and have hit upon a problem.
I have a number of tutors containing 3 pieces of information (name, email, mobile number). There can be loads of these and rather than muck around, I've come up with the following solution.
My solution looks like this
Expand|Select|Wrap|Line Numbers
- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace class_list_test
- {
- class Program
- {
- static void Main(string[] args)
- {
- tester m = new tester();
- List<tester> t = new List<tester>();
- m.a = 1;
- m.c = "wibble";
- m.d.Add(3.14);
- m.d.Add(3.28);
- t.Add(m);
- m.a = 2;
- m.c = "wobble";
- m.d.Add(6.02);
- m.d.Add(6.16);
- t.Add(m);
- m.a = 3;
- m.c = "snurfle";
- m.d.Add(9.44);
- m.d.Add(9.58);
- t.Add(m);
- m.a = 4;
- m.c = "snarfle";
- m.d.Add(7.33);
- m.d.Add(7.47);
- t.Add(m);
- printstuff(t);
- }
- private static void printstuff(List<tester> r)
- {
- for (int n = 0; n < r.Count; ++n)
- Console.WriteLine("{0}, {1}, {2}, {3}", r[n].a, r[n].c, r[n].d[0], r[n].d[1]);
- Console.ReadLine();
- }
- }
- public class tester
- {
- public int a;
- public string c;
- public List<double> d = new List<double>();
- }
- }
Expand|Select|Wrap|Line Numbers
- m = new tester();
Am I better off adding a get/set in the tester class will I still need a new instance of tester() after each add?
Paul