C# 从目录条目C创建字节[]#

C# 从目录条目C创建字节[]#,c#,arrays,vb.net,byte,directoryentry,C#,Arrays,Vb.net,Byte,Directoryentry,您好,我已将此示例从VB.Net转换为C# 但我不知道如何翻译以下代码行: 'Get the objectSID which is Byte array Dim objectSid As Byte() = DirectCast(deTempForSID.Properties("objectSid").Value, Byte()) 正如我所理解的,它必须是这样的,但我不确定,因为它不工作并且返回数组溢出: byte[] objectSid = BitConverter.GetBytes(deTe

您好,我已将此示例从VB.Net转换为C# 但我不知道如何翻译以下代码行:

'Get the objectSID which is Byte array
Dim objectSid As Byte() = DirectCast(deTempForSID.Properties("objectSid").Value, Byte())
正如我所理解的,它必须是这样的,但我不确定,因为它不工作并且返回数组溢出:

byte[] objectSid = BitConverter.GetBytes(deTempForSID.Properties.Contains("objectSid"));

请有人解释一下如何将这段代码从VB.Net正确地翻译成C#?

这是因为
包含
返回布尔值。改用
值。

汉斯·帕桑善意地建议正确答案是:

(byte[])deTempForSID.Properties["objectSid"].Value

为什么现在要转换Contains()而不是Value??bool不是Sid,所以你只是随机输入了其他东西?改为使用
(byte[])deTempForSID.Properties[“objectSid”].Value
。您使用
Value
尝试了什么?数组索引器不是C#中的括号,而是括号(
[
]
)。
(byte[])deTempForSID.Properties[“objectSid”]。Value
。。。你在搜索“DirectCast C#”吗?汉斯·帕桑,你正确地回答了我的第一个问题,但我无法理解,因为我太累了。。。你能把这一排作为答案吗?