Could not resolve type: Issue while I am casting a custom class in c#

坚强是说给别人听的谎言 提交于 2019-12-11 16:17:54

问题


It is very weird problem.

I have ProfileBase class and created a list from it

List<ProfileBase> profileLists = ....

well after i add items to this list from another list name is QuickSearchProfile which is derived from ProfileBase also.

var _list = new List<ProfileBase>();

_list.AddRange((IEnumerable<QuickSearchProfile>)list);

but I cant cast like that

var item = (profileLists[indexPath.Row] as QuickSearchProfile);

or like that

var item = (QuickSearchProfile)profileLists[indexPath.Row]; 

in both situation, item returns null. Actually when I put a breakpoint, I can see that profileLists[indexPath.Row]'s type is QuickSearchProfile

Where is my mistake?


回答1:


save item uncasted and get its full typename and output it, then get typeof(QuickSearchProfile) and do the same. THe CLR is sayin they arent the same - I believe it



来源:https://stackoverflow.com/questions/26899487/could-not-resolve-type-issue-while-i-am-casting-a-custom-class-in-c-sharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!