简体   繁体   English

从 VB 转换为 C#

[英]Convert from VB to C#

I want to translate these line of code from VB.NET to C# and when I check online from我想将这些代码行从 VB.NET 翻译成 C#,当我从

If (userAccountControl And 65536) Then
                                        Dont_Expire_Password = 1
                                  Else
                                        Dont_Expire_Password = 0
                                  End If

Link 1链接 1

Link 2链接 2

I get something我得到了一些东西

 if (userAccountControl & 65536)
    {
    }

But I get error in但我得到错误

Cannot implicitly convert type 'int' to 'bool'无法将类型“int”隐式转换为“bool”

I assume this mean我认为这意味着

if (userAccountControl == 65536)

Correct me if I am wrong !如果我错了,请纠正我!

In C# int doesn't implicitly convert to a bool , so you need to write your expression to handle this.在 C# 中 int 不会隐式转换为bool ,因此您需要编写表达式来处理此问题。 In your case it would be:在您的情况下,它将是:

if((userAccountControl & 65536) != 0)
{
  // Do something
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM