vb.net - Collection with sub- collection -
lets suppose have forum 1 thread 3 posts.
i want final result:
dim myfourm new fourm myfourm.thread.add(545)''for ex 545 mean thread id. myforum.thread(0).post(1).username
thread should collection of integer(=thread id) post should collection of post type
so in case, code "chose first thread, , second post , retrieve username of write post"
public class fourm 'thread should inside class , background code end class public class post public property username string public property postcontent string end class
just clear: goal organize collections. each thread should have own posts.
i chose forum @ example, else .. if not clear please me .. not native language(but not worry - can read. ;))
in correct project iam using dictionary. want explore more.. anyway, tried "you have use collection of thread each thread instance has collection of post" , result:
public class mainfrm private sub form1_load(sender object, e eventargs) handles mybase.load dim myforum new forum myforum.thread.add(500)' id's myforum.thread.add(120) myforum.thread(0).posts.add(new forumpost() {.postcontent = "therad id: 500 | post: 1#", .username = "don"}) myforum.thread(0).posts.add(new forumpost() {.postcontent = "therad id: 500 | post: 2#", .username = "shon"}) myforum.thread(0).posts.add(new forumpost() {.postcontent = "therad id: 500 | post: 3#", .username = "ron"}) myforum.thread(1).posts.add(new forumpost() {.postcontent = "therad id: 120 | post 1#", .username = "emi"}) ithread = 0 myforum.thread.count - 1 ipost = 0 myforum.thread(ithread).posts.count - 1 static pst new forumpost pst = myforum.thread(ithread).posts(ipost) console.writeline($"content:{pst.postcontent}, username post it:{pst.username}") next next end sub end class public class forum public property thread new threadcollection end class public class forumthread inherits list(of integer) public property posts new postcollection sub new(id integer) end sub end class public class threadcollection inherits list(of forumthread) public overloads sub add(byval id integer) mybase.add(new forumthread(id)) end sub end class public class forumpost public property username string public property postcontent string end class public class postcollection inherits list(of forumpost) end class ' content:therad id: 500 | post: 1#, username post it:don ' content:therad id: 500 | post: 2#, username post it:shon ' content:therad id: 500 | post: 3#, username post it:ron ' content:therad id: 120 | post 1#, username post it:emi
now question is: supposed this? or there better way write this?
Comments
Post a Comment