vb.net - Using For each loop without try-catch in Visual basic 2012 -
i have simple code:
public class form1 dim strfriends(4) string private sub arrayelement_click(sender object, e eventargs) handles arrayelement.click clearlist() 'try each item string in strfriends lstfriends.items.add(item) next 'catch 'end try end sub private sub clearlist() lstfriends.items.clear() end sub private sub form1_load(sender object, e eventargs) handles me.load strfriends(0) = "tom" strfriends(1) = "kate" strfriends(2) = "bill" strfriends(3) = "harry" end sub
end class
if try-catch removed, system.argumentnullexception
compulsory use try catch block use each?
try this:
if not string.isnullorempty(item) ' add item end if
update:
you can check see if array has in it, this:
if strfriends.length > 0 ' array end if
Comments
Post a Comment