小编bev*_*qua的帖子

c#检查端口是否正在主动监听?

我使用以下代码来实现此目标:

    public static bool IsServerListening()
    {
        var endpoint = new IPEndPoint(IPAddress.Parse("201.212.1.167"), 2593);
        var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

        try
        {
            socket.Connect(endpoint, TimeSpan.FromSeconds(5));
            return true;
        }
        catch (SocketException exception)
        {
            if (exception.SocketErrorCode == SocketError.TimedOut)
            {
                Logging.Log.Warn("Timeout while connecting to UO server game port.", exception);
            }
            else
            {
                Logging.Log.Error("Exception while connecting to UO server game port.", exception);
            }

            return false;
        }
        catch (Exception exception)
        {
            Logging.Log.Error("Exception while connecting to UO server game port.", exception);
            return false;
        }
        finally
        {
            socket.Close();
        } …
Run Code Online (Sandbox Code Playgroud)

c# sockets

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

需要C#Nullable显式强制转换

    private bool? _success;
    public bool Success
    {
        get
        {
            return _success ?? (_success = false);
        }
    }
Run Code Online (Sandbox Code Playgroud)

为什么编译器找不到正确的操作数总是假的,并且需要我将其转换为bool

c#

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

为什么这段js会抛出DOM异常?

我无法弄清楚为什么这个小提琴会抛出

未捕获错误:InvalidStateError:DOM异常11

function url(){
 return '/echo/js/?js=' + 5 + Math.floor(Math.random()*900);
}

function poll(done){
    var xhr = new XMLHttpRequest();
    xhr.onreadystatechange = function(){
        if(xhr.status === 200 && xhr.readyState === 4){
            var foo = xhr.responseText;
            done(parseInt(foo));
        }
    };
    xhr.open('get',url(),false);
    xhr.send(null);
}

var button = document.querySelector('#poller');
var price = document.querySelector('#price');

button.addEventListener('click', function(){
    poll(function(data){
        price.innerText = data;
    });
},false);
Run Code Online (Sandbox Code Playgroud)

javascript xmlhttprequest

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

UserControl中的ASP.NET内容占位符

我希望能够做到这样的事情:

<uc:MyUC>
    <CustomContent>
        <span id="name">johnny the assasin</span>
    </CustomContent>
</uc:MyUC>
Run Code Online (Sandbox Code Playgroud)

并具有该控件能够呈现

hello <b><span id="name">johnny the assasin</span></b>
Run Code Online (Sandbox Code Playgroud)

但我似乎无法找到一种方法来公开一个属性,让我可以编写任何我想要的标记,就好像我的用户控件上有一个内容占位符一样

这样的事情甚至可能吗?

asp.net user-controls

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

javascript中的正则表达式问题

"foo = '@test.bar';\nfooa = @test.darn;".match(/@([a-z][a-z\.-_]*)/igm)
Run Code Online (Sandbox Code Playgroud)

为什么这匹配

["@test.bar", "@test.darn;"]
Run Code Online (Sandbox Code Playgroud)

而不仅仅是

["@test.bar", "@test.darn"]
Run Code Online (Sandbox Code Playgroud)

javascript regex

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

C#扩展所有[Flag]枚举?

public static bool Get(this EventFlags flags, EventFlags flag)
{
    return ((flags & flag) != 0);
}

public static void Set(this EventFlags flags, EventFlags flag, bool value)
{
    if (value)
        flags |= flag;
    else
        flags &= ~flag;
}
Run Code Online (Sandbox Code Playgroud)

基本上我想为任何[Flag]枚举做这件事,例如

[Flags]
public enum FlagEn
{
   None = 0x0000,
   UseSkill = 0x0001
}
Run Code Online (Sandbox Code Playgroud)

c#

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

为什么抛出System.FormatException?

这是一个错误string.Format或什么?

// Act
string l = "This is an UnitTest embedded resource.";
string r = "Please do not remove or change. Sincerely yours, {0}".FormatWith(model.Username);
string expected = "[\r\n\t{0}\r\n\r\n\r\n]\r\n{\r\n\t\r\n\t{1}\r\n\r\n}".FormatWith(l, r);
Run Code Online (Sandbox Code Playgroud)

FormatWith方法只是语法糖的延伸.

public static string FormatWith(this string text, params object[] args)
{
    return string.Format(text, args);
}
Run Code Online (Sandbox Code Playgroud)

c#

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

如何在JavaScript或jQuery中获取div高度值?

我需要div在JavaScript或jQuery中获得高度,并在CSS中改变它的价值.

我怎么能用jQuery或JavaScript做到这一点?

javascript jquery

-4
推荐指数
1
解决办法
5165
查看次数