小编Nat*_*ith的帖子

如何用JavaScript更改元素的类?

如何onclick使用JavaScript 更改HTML元素的类以响应事件?

html javascript dom

2650
推荐指数
22
解决办法
248万
查看次数

如何将查询字符串解析为.NET中的NameValueCollection

我想解析一个字符串,如p1=6&p2=7&p3=8一个NameValueCollection.

当您无法访问该Page.Request对象时,最优雅的方法是什么?

.net parsing query-string

181
推荐指数
6
解决办法
13万
查看次数

如何取消订阅C#中特定类的事件的所有处理程序?

基本前提:

我有一个房间,当一个阿凡达"进入"房间内的所有头像时,它会发布一个事件.当阿凡达离开房间时,我希望它删除该房间的所有订阅.

在将"阿凡达"添加到新房间并订阅新房间的活动之前,我怎样才能最好地取消订阅房间中所有活动的阿凡达?

代码如下:

class Room
{
   public event EventHandler<EnterRoomEventArgs> AvatarEntersRoom;
   public event EvnetHandler<LeaveRoomEventArgs> AvatarLeavesRoom;
   public event EventHandler<AnotherOfManyEventArgs> AnotherOfManayAvatarEvents;


   public void AddPlayer(Avatar theAvatar)
   {
      AvatarEntersRoom(this, new EnterRoomEventArgs()); 

      AvatarEntersRoom += new EventHandler<EnterRoomEventArgs>(theAvatar.HandleAvatarEntersRoom);

      AvatarLeavesRoom += new EventHandler<EnterRoomEventArgs>(theAvatar.HandleAvatarEntersRoom);

      AnotherOfManayAvatarEvents += new EventHandler<EnterRoomEventArgs>(theAvatar.HandleAvatarEntersRoom);          

   }

}

class Avatar
{
   public void HandleAvatarEntersRoom(object sender, EnterRoomEventArgs e)
   {
       Log.Write("avatar has entered the room");
   }

   public void HandleAvatarLeaveRoom(object sender, LeaveRoomEventArgs e)
   {
       Log.Write("avatar has left room");
   }

   public void HandleAnotherOfManayAvatarEvents(object sender, AnotherOfManyEventArgs e)
   {
       Log.Write("another avatar event has …
Run Code Online (Sandbox Code Playgroud)

.net c# events

33
推荐指数
2
解决办法
3万
查看次数

c#中实现优先级排队队列的最快集合是什么?

我需要为游戏服务器上的消息实现FIFO队列,因此它需要尽可能快.每个用户都会有一个队列.

队列将具有maxiumem大小(比方说2000).在运行时,大小不会改变.

我需要优先处理消息,如果队列通过向后工作并在添加新消息之前删除较低优先级的消息(如果存在),则达到其最大大小.

优先级是int,可能的值为1,3,5,7,10.

可以有多条具有相同优先级的消息.

一旦分配,消息就不能改变其优先级.

应用程序是异步的,因此需要锁定对队列的访问.

我目前正在使用LinkedList作为底层存储来实现它,但是担心搜索和删除节点会使其锁定时间过长.

这是我目前的基本代码:

public class ActionQueue
{
    private LinkedList<ClientAction> _actions = new LinkedList<ClientAction>();
    private int _maxSize;

    /// <summary>
    /// Initializes a new instance of the ActionQueue class.
    /// </summary>
    public ActionQueue(int maxSize)
    {
        _maxSize = maxSize;
    }

    public int Count
    {
        get { return _actions.Count; }            
    }

    public void Enqueue(ClientAction action)
    {
        lock (_actions)
        {
            if (Count < _maxSize)
                _actions.AddLast(action);
            else
            {
                LinkedListNode<ClientAction> node = _actions.Last;
                while (node != null)
                {
                    if (node.Value.Priority < …
Run Code Online (Sandbox Code Playgroud)

c#

7
推荐指数
2
解决办法
4003
查看次数

如何从Page.Master转换为ASP.NET中的特定母版页

我有一个BasePage继承自的System.Web.UI.Page,并且每个继承了BasePagewill的页面都有相同的母版页.

如何将Page.MasterBasePage转换为特定的母版页,以便我可以访问它的属性?

asp.net-2.0

3
推荐指数
1
解决办法
2956
查看次数

如何在无序集合中存储Integer和Boolean键值对?

我需要在.NET中存储(integer,boolean)键值对的列表

当我使用字典时,它会重新排序它们.是否有内置的集合来处理这个问题.

.net

1
推荐指数
1
解决办法
1934
查看次数

如何在AS3中为弧中的显示对象设置动画?

这是一个仅限闪存AS3项目的游戏.

玩家用枪控制角色.通过点击屏幕,枪可以将弧形导弹发射到点击的点.

什么是计算导弹每个框架的x和y坐标的最佳方法?

math flash physics actionscript-3

1
推荐指数
1
解决办法
1361
查看次数