1

As recommended in my earlier question, the best way to store customer data would be in a list of class instances (I think thats what it's called :p). I've created the list var customers = new List<Customer>(); in a startup method, and right after, when I load any values from a text file into the program, I'm doing this:

static void loadData() //Load data from Database
{            
    customers.Add(new Customer
    {
        ID = "001",
        Name = "Nathan",
    }
}

I know I'm not doing it correctly though, and I can't quite figure out the correct way. Right now I'm not extracting from the file, I'm just trying to add something to the list. Obviously I'm missing a closing parenthesis, but I'm not quite sure where it would go.

If someone could help me add one thing to this list, I should be able to figure out the rest on my own.

Thanks! :)

Community
  • 1
  • 1
Nat
  • 890
  • 3
  • 11
  • 23

2 Answers2

9

.Add() is a method and there is a parenthesis missing.

static void loadData() //Load data from Database
{            
    customers.Add(new Customer
    {
        ID = "001",
        Name = "Nathan",
    });
}

It may be a good habit for you, to write the methods first, including the parenthesis and add all the parameters afterwards into it. This way you would eliminate those errors.

What I mean is:

Start with customers.Add();

Then add the new Customer class instance: customers.Add(new Customer {});

And finally add your actual data customers.Add(new Customer { //Here'll be dragons});

Marco
  • 22,856
  • 9
  • 75
  • 124
  • 1
    :facepalm: I should have been able to figure that out! If you can't tell, I still don't quite know what I'm doing :P Thanks again! – Nat Oct 09 '13 at 20:21
  • 1
    Everybody has started out somewhere. Keep on going, you will get the hang of it fairly soon. – Marco Oct 09 '13 at 20:21
1
   static void loadData() //Load data from Database
    {            
        customers.Add(new Customer{ ID = "001", Name = "Nathan" });
    }
E.J. Brennan
  • 45,870
  • 7
  • 88
  • 116