在C#中,為什么不能將列表<string>對(duì)象存儲(chǔ)在列表<Object>變量中?似乎列表對(duì)象不能存儲(chǔ)在C#中的列表變量中,甚至不能以這種方式顯式轉(zhuǎn)換。List<string> sl = new List<string>();List<object> ol;ol = sl;結(jié)果不能隱式轉(zhuǎn)換類(lèi)型。System.Collections.Generic.List<string>到System.Collections.Generic.List<object>然后.。List<string> sl = new List<string>();List<object> ol;ol = (List<object>)sl;結(jié)果不能轉(zhuǎn)換類(lèi)型System.Collections.Generic.List<string>到System.Collections.Generic.List<object>當(dāng)然,您可以從字符串列表中提取所有內(nèi)容,并一次將其放回一個(gè)字符串列表中,但這是一個(gè)相當(dāng)復(fù)雜的解決方案。
在C#中,為什么不能將列表<string>對(duì)象存儲(chǔ)在列表<Object>變量中?
鴻蒙傳說(shuō)
2019-06-21 15:52:32