我對C#相當陌生,但我正在尋找將對象轉換爲無符號短褲的數組。原始數據是作爲對象傳遞的WORD(數值WORD)數組。我嘗試了以下,但不斷收到錯誤。將對象轉換爲c#中的Ushort數組#
object temp = Agent.Port("PumpPressure1_01").Value;
ushort[] PP1_01 = ((IEnumerable)temp).Cast<object>()
.Select(x => x == null ? x.ToUshort())
.ToArray();
當我運行此我得到以下錯誤:
'System.Collections.Generic.IEnumerable<T>' requires '1' type arguments.
我時,我得到上述錯誤的命名空間是:
using System.Linq;
using System.Text; // Don't think this is required but added it in case
如果我添加下面的命名空間:
using System.Collections;
using System.Collections.Generic;
我ge t出現以下錯誤。
'System.Linq.ParalleIEnumerable.Select<TTSource,TResult>()' is not supported by the language
我敢肯定,這是一個明顯的問題,但我一直在狩獵淨一會兒,並不能找到一個解決方案。我最好的猜測是Select
函數是不正確的,因爲它最初設計用來將一個對象轉換爲一個字符串數組。
任何幫助將是偉大的。
感謝
這不是合法的語法,你能提供真實的代碼嗎? '.Select(x => x == null?x.ToUshort())'。另外,如何定義'.ToUshort'? –