【发布时间】:2011-12-10 17:55:01
【问题描述】:
我在 C# 中使用 jabber.net,有一个怪癖让我感到困惑,所以希望有人能解释它是如何做到的。我从 C++ 背景对 C# 还是很陌生,所以这可能是一个误解
我正在创建一个只读 JID 来保存我需要进入的房间:
private readonly JID messagingRoomJID;
public MyClass
{
// Reads from database but for purpose of this question
messagingRoomJID = new JID("user@myserver");
}
稍后我想加入一个让我感到困惑的房间
conferenceManager = new ConferenceManager();
conferenceManager.Stream = xmppClient;
// Before entering this room messagingRoomJID.Resource == null
theRoom = conferenceManager.GetRoom(messagingRoomJID);
// But now messagingRoomJID.Resource contains my username
但是 Resource 是如何改变的呢?该变量是只读的,但也不应该通过 const 引用传递,那么它是如何更新的呢?
看起来我可以这样做,但我不确定它是否明智:
theRoom = conferenceManager.GetRoom(new JID(messagingRoomJID));
【问题讨论】: