的問題是主要的中間,在讀取一個對象怎麼能不等於自己? (SSIS腳本任務)
if ((byte[])Dts.Variables["User::EncryptionKey"].Value == noKey)
當個getEncryptionKey「失敗」,並返回NOKEY的「如果」仍然採取「其他」的路徑和我不線路不明白爲什麼。我試着用相同的結果。
if (noKey.Equals((byte[])Dts.Variables["User::EncryptionKey"].Value))
除非到NOKEY每個引用以某種方式實例字節的新副本[0]我不明白他們怎麼可以不等。我已經經歷了無數次,他們當然看起來是平等的。
private static byte[] noKey = new byte[0];
public void Main()
{
int keyLen = 32;
Dts.Variables["User::EncryptionKey"].Value =
GetEncryptionKey((string)Dts.Variables["User::EncryptionKeyAsHex"].Value, keyLen);
if ((byte[])Dts.Variables["User::EncryptionKey"].Value == noKey)
{
Dts.TaskResult = (int)ScriptResults.Failure;
}
else
{
Dts.TaskResult = (int)ScriptResults.Success;
}
}
private static byte[] GetEncryptionKey(string hexString,int numBytes)
{
return noKey; //<-this definitely does get hit!
}
那麼,你正在執行參考比較。如果分配給Value屬性(或獲取它)需要一個數組的副本,這將解釋的東西......你可以減少這個[mcve]? (這裏有很多代碼,其中大部分看起來像沒有必要再現這個...) –
[檢查兩個字節數組的相等性]可能的重複(https://stackoverflow.com/questions/18472867/checking-equality -for-two-byte-arrays) – Eris
看起來你正在自動裝箱。請參閱「[在Java中比較兩個基元數組?](https://stackoverflow.com/questions/630808/compare-two-arrays-of-primitives-in-java)」。 –