我要生成從第一個列表(對象的列表)的隨機數,並把它在第二個列表以獲得一個隨機的連接ID,使原來的ID和之間連接的數據隨機ID如何我可以通過索引從第一個列表中的項目和哪種類型的我要投它我怎麼可以得到存儲在列表
public class OneHub :Hub
{
static List<UserId> ConnectedUser = new List<UserId>();
static List<MessageDetail> CurrentMessage = new List<MessageDetail>();
static List<ConnectionsId> Connection = new List<ConnectionsId>();
public void Connect(string id)
{
if (ConnectedUser.Count(x => x.ConnectionId == id) == 0)
{
ConnectedUser.Add(new UserId { ConnectionId = id });
if (ConnectedUser.Count != 0 || ConnectedUser.Count != 1)
{
Random r = new Random();
int x = r.Next(0,ConnectedUser.Count);
(object)ConnectedUser.item[x];
Connection.Add(new ConnectionsId {ConnectionId=id,ConnectionId2= })
}}}
請不要將您的代碼作爲圖像發佈。它不容易被搜索,不能被複制/粘貼,並且是浪費帶寬。將相關代碼作爲* text *複製到您的問題中。 – mason
我不明白爲什麼這是一個循環。如果你只想連接一個人,爲什麼你需要一個循環? – Hogan
好感謝@mason –