C# array not quite working right
Go to solution
Solved by RononDex,
You're replacing your first object with a different object.
clients[ccount] = new client { clientid = ccount}; // creating new object, setting the idclients[ccount] = new client {Name = name}; // creating another new, different object, and setting the name (id isn't set)The ID is always zero because that is the default value of an int property. When you declare your second object, it wont have a value assigned to the id. To fix it, assign all properties at once or create the object before you add it to the array.
clients[ccount] = new client {clientid = ccount, Name = name};
I replaced ccount with i (the for loop counter) and missed to replace some ccount calls. Edited and should be fixed.
EDIT: Ah sry, I thought you were talking to me lol

Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now