winforms - Specified cast is not valid -
i tried best cast value how keep getting exception. hope 1 guide me in right path.
here code
this type service
 public enum channelcodetype {      /// <remarks/>     a1,      /// <remarks/>     a2,      /// <remarks/>     a3,      /// <remarks/>     a4, }   in winform have list box generate these channels ,i try cast selected channels in list box , pass channel type gives me hard time.
 channelcodetype[] channelcodes; channelcodes=lbsearch.selecteditems.tostring().cast<channelcodetype>().toarray();   then tried below failed
string[] destination = new string[lbsearch.items.count];         lbsearch.items.copyto(destination, 0);         channelcodes = destination.cast<channelcodetype>().toarray();   in both way keeps complaining cast not valid.
channelcodes = destination.select(e => (channelcodetype)enum.parse(typeof(channelcodetype),e)).toarray();   try above.
the problem current approach can't cast string enum directly. have parse it.
Comments
Post a Comment