我有这段代码,它工作正常:
News news_data[] = new News[] {
new News("1","news 1","this is news 1"),
new News("2","news 2","this is news 2"),
new News("2","news 1","this is news 2"),
};
在这段代码中,我添加了 3 个新对象,但我必须在循环中动态添加它们。我怎样才能做到这一点?我其实不明白这个数组结构。请向我解释这段代码,如果你能让它简单的话
我试过了,但它不起作用:
News news_data[];
for(i=1;i<3;i++){
news_data=new News[] {
new News("1","news 1","this is news 1"),
new News("2","news 2","this is news 2"),
new News("2","news 1","this is news 2"),
};
}