怎么了?我似乎无法关闭此代码

时间:2017-04-03 00:32:46

标签: c#

我无法弄清楚如何正确地关闭它,无论我在哪里添加一个括号都会破坏代码。 感谢您的帮助,谢谢:)

            int NewID = Convert.ToInt32(Adapter.InsertQuery()); // new relationship id
            if (!Session.GetHabbo().Relationships.ContainsKey(Them))
                Session.GetHabbo().Relationships.Add(Them, new Relationship(NewID, Them, 3)); // create the relationship

            Session.GetHabbo().GetMessenger().UpdateFriend(Them, Session, true);
        }

        else

          {
            Habbo Habbo = PlusEnvironment.GetHabboById(Them);
            if (Habbo != null)
            {
                MessengerBuddy Bud = null;
                if (Session.GetHabbo().GetMessenger().TryGetFriend(Them, out Bud))
                    Session.SendMessage(new FriendListUpdateComposer(Session, Bud));
            }
        }
        return false;
    }

P.S我还是新手。

1 个答案:

答案 0 :(得分:2)

这似乎是一个简单的修复,但如果您格式化代码,这种东西通常会突出。在Visual Studio中,您可以按 Ctrl + K Ctrl + D (连续)并且它' ll将您的代码格式化为默认值。

int NewID = Convert.ToInt32(Adapter.InsertQuery()); // new relationship id
if (!Session.GetHabbo().Relationships.ContainsKey(Them))
    Session.GetHabbo().Relationships.Add(Them, new Relationship(NewID, Them, 3)); // create the relationship

    Session.GetHabbo().GetMessenger().UpdateFriend(Them, Session, true);
}
else
{
    Habbo Habbo = PlusEnvironment.GetHabboById(Them);
    if (Habbo != null)
    {
        MessengerBuddy Bud = null;
        if (Session.GetHabbo().GetMessenger().TryGetFriend(Them, out Bud))
            Session.SendMessage(new FriendListUpdateComposer(Session, Bud));
        }
    }
    return false;
}

好的。现在已经完成了。一般来说,你错过了if语句的开头括号。

int NewID = Convert.ToInt32(Adapter.InsertQuery()); // new relationship id
if (!Session.GetHabbo().Relationships.ContainsKey(Them))
{ // Added here
    Session.GetHabbo().Relationships.Add(Them, new Relationship(NewID, Them, 3)); // create the relationship

    Session.GetHabbo().GetMessenger().UpdateFriend(Them, Session, true);
}
else
{
    Habbo Habbo = PlusEnvironment.GetHabboById(Them);
    if (Habbo != null)
    {
        MessengerBuddy Bud = null;
        if (Session.GetHabbo().GetMessenger().TryGetFriend(Them, out Bud))
        { // Added here.
            Session.SendMessage(new FriendListUpdateComposer(Session, Bud));
        }
    }
    return false;
}

因此,如果您添加// Added here条评论中提到的那两个括号,那么这应该有效。