msglist.cs

来自「c#网络聊天室源码c#网络聊天室源码c#网络聊天室源码」· CS 代码 · 共 94 行

CS
94
字号
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
//该源码下载自www.51aspx.com(51aspx.com)

namespace SimpleChat
{
    public class MsgList
    {
        int msgNum = 8;
        public int msgNowID;

        MsgStructure [] messageList; 
        public MsgList()
        {
            msgNowID = 0;
            messageList = new MsgStructure[msgNum];
        }
        public void MsgPush(string msg)
        {
            msgNowID++;
            MsgStructure tmpMsg = new MsgStructure(msgNowID, msg);
            for(int i=0;i<msgNum-1;i++)
            {
                messageList[i] = messageList[i + 1];
            }
            messageList[msgNum - 1] = tmpMsg;
        }
        public string[] GetMsg(int nowID)
        {
            int tmpCount = msgNowID - nowID;
            string[] tmpStr;
            if (tmpCount > 0)
            {
                tmpStr = new string[tmpCount];
                int tmpBig = tmpCount>=8?8:tmpCount;
                for(int i=0;i<tmpBig;i++)
                {
                    tmpStr[i] = "<br />" + messageList[msgNum - tmpBig + i].MsgBody;
                }
                return tmpStr;
            }
            else
            {
                return null;
            }
        }
    }
    class MsgStructure
    {
        int msgID;
        public int MsgID
        {
            get
            {
                return  msgID;
            }

            set
            {
                msgID = value;
            }
        }
        string msgBody;
        public string MsgBody
        {
            get
            {
                return msgBody;
            }
            set
            {
                msgBody = value;
            }
        }
        public MsgStructure(int id)
        {
            msgID = id;
            msgBody = "";
        }
        public MsgStructure(int id,string msg)
        {
            msgID = id;
            msgBody = msg;
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?