c# - Create a empty array of points -
i'm trying create empty array of points, i'm using following
point[] listapontos = new[]; //should create empty point array later use doesn't. point ponto = new point(); //a no coordinates point later use (int = 1; <= 100; i++) //cycle create 100 points, x , y coordinates { ponto.x = * 2 + 20; ponto.y = 20; listapontos[i] = ponto; } i'm having trouble, because can't create empty array of points. create empty array of strings using list, since need 2 elements, list isn't useful here.
any hints? (hints problem welcome)
// should create empty point array later use doesn't.
no, you've specified isn't valid syntax. if want empty array, use of:
point[] listapontos = new point[0]; point[] listapontos = new point[] {}; point[] listapontos = {}; however, you've got array 0 elements, statement:
listapontos[i] = ponto; ... throw exception. sounds should either use list<point>, or create array of size 101:
point[] listapontos = new point[101]; (or create array of size 100, , change indexes use - you're not assigning index 0.)
it's important understand in .net, array object doesn't change size after creation. that's why it's convenient use list<t> instead, wraps array, "resizing" (by creating new array , copying values) when needs to.
Comments
Post a Comment