1

我有一个 if 语句,如果两个或多个条件 = true,我希望它为 true。我尝试使用 && 运算符,但 VS2012 只是抱怨说;

错误运算符“&&”不能应用于“bool”和“Microsoft.Exchange.WebServices.Data.DelegateFolderPermissionLevel”类型的操作数

我尝试了三种方法:

if (item.Permissions.CalendarFolderPermissionLevel != DelegateFolderPermissionLevel.Editor && item.Permissions.InboxFolderPermissionLevel != DelegateFolderPermissionLevel.Editor)
            {

                item.Permissions.CalendarFolderPermissionLevel = DelegateFolderPermissionLevel.Editor;

            }

     if (item.Permissions.CalendarFolderPermissionLevel && item.Permissions.InboxFolderPermissionLevel != DelegateFolderPermissionLevel.Editor)
            {
                item.Permissions.CalendarFolderPermissionLevel = DelegateFolderPermissionLevel.Editor;
            }

if ((item.Permissions.CalendarFolderPermissionLevel = DelegateFolderPermissionLevel.Editor) && (item.Permissions.InboxFolderPermissionLevel != DelegateFolderPermissionLevel.Editor))
            {
                item.Permissions.CalendarFolderPermissionLevel = DelegateFolderPermissionLevel.Editor;
            }

在网上找不到任何有用的东西。我将如何写这样的声明?它只适用于一个条件..

4

2 回答 2

2

尝试在每个条件周围加上括号:

if ((item.Permissions.CalendarFolderPermissionLevel != DelegateFolderPermissionLevel.Editor) && 
    (item.Permissions.InboxFolderPermissionLevel != DelegateFolderPermissionLevel.Editor))
{
    item.Permissions.CalendarFolderPermissionLevel = DelegateFolderPermissionLevel.Editor;
}
于 2013-08-30T16:13:33.437 回答
1

Mr.pswg 是对的,它可以解决您的问题,但我在这里告诉您代码中的问题
您的前两次尝试

if (item.Permissions.CalendarFolderPermissionLevel != DelegateFolderPermissionLevel.Editor && item.Permissions.InboxFolderPermissionLevel != DelegateFolderPermissionLevel.Editor)

if (item.Permissions.CalendarFolderPermissionLevel && item.Permissions.InboxFolderPermissionLevel != DelegateFolderPermissionLevel.Editor)

失败,因为您不知道运算符的优先顺序
使用此链接http://msdn.microsoft.com/en-us/library/2bxt6kc4.aspx

编译器将其解释为TRUE && item.Permissions.InboxFolderPermissionLevel

在第一种情况下,对于其他情况也是如此,这就是它给你错误的原因

第三次尝试

if ((item.Permissions.CalendarFolderPermissionLevel = DelegateFolderPermissionLevel.Editor) && (item.Permissions.InboxFolderPermissionLevel != DelegateFolderPermissionLevel.Editor))

第一个条件的运算符将是“==”而不是“=”:)
“=”是我猜的 vb.net。
我希望你现在很清楚
,你的答案将由 pswg 给出

 if ((item.Permissions.CalendarFolderPermissionLevel != DelegateFolderPermissionLevel.Editor) && 
    (item.Permissions.InboxFolderPermissionLevel != DelegateFolderPermissionLevel.Editor))
{
    item.Permissions.CalendarFolderPermissionLevel = DelegateFolderPermissionLevel.Editor;
}
于 2013-08-31T16:30:39.340 回答