【发布时间】:2015-03-24 16:05:36
【问题描述】:
您好,我已将此示例 https://code.msdn.microsoft.com/windowsdesktop/VBGetUserGroupInAD-a94dc080 从 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#?
【问题讨论】:
-
为什么现在转换 Contains() 而不是 Value? bool 不是 Sid。
-
所以您只是随机输入了其他内容?请改用
(byte[])deTempForSID.Properties["objectSid"].Value。 -
什么你试过
Value?数组索引器在 C# 中不是括号,它们是括号([和])。 -
(byte[])deTempForSID.Properties["objectSid"].Value... 你搜索过“DirectCast C#”吗? -
Hans Passant,您第一次正确回答了我的问题,但我无法理解,因为我太累了...您可以将这一行作为答案吗?
标签: c# arrays vb.net byte directoryentry