小编Evk*_*Evk的帖子

VS调试问题,谁能帮我解释一下这个?

一段C#代码

var isTrue = (new List<int>{1,2,3} is IEnumerable<object>);
Run Code Online (Sandbox Code Playgroud)

我得到false了代码执行的结果,但是当我将该代码复制到WATCH窗口时,结果是true.

c# debugging

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

在Forms-Authentication中动态使用cookie

目前我有两种方式:

  1. 当我设置我的web.config cookieless="UseCookies"我的网址看起来:

    http://example.com/Stuff

    <sessionState timeout="60" cookieless="UseCookies"/>

  2. 当我设置cookieless="true"我有这样的网址

    http://example.com/%28S%28uanyuxwgaviyonky0lxwq3vq%29%29/Stuff

    <sessionState timeout="60" cookieless="true"/>


我可以设置cookieless属性动态吗?就像是

if(/*condition*/)
{
    sessionState .cookieless = "true";
}
else
{
    sessionState .cookieless = "UseCookies";
}
Run Code Online (Sandbox Code Playgroud)

这必须是SessionStartGlobal.asax中的某个地方

c# asp.net forms-authentication session-cookies

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

ConditionalWeakTable - GC.Collect() 行为,为什么它没有按预期运行?

为什么我的weakRef.Target在第二次射击时仍然存在?

这可能是一个错误吗?如果不是,错误在哪里?

结果:

weakRef.Target is alive = True, expected true because inst keep a hold on SomeClass.
weakRef.Target is alive = True, expected false, because there is no more ref on SomeClass.
Run Code Online (Sandbox Code Playgroud)

代码:

public static class DelegateKeeper
    {
        private static ConditionalWeakTable<object, Action> cwtAction = new ConditionalWeakTable<object, Action>();
        public static void KeepAlive(Action action) => cwtAction.Add(action.Target, action);
    }

    public class SomeClass
    {
        public void DoSomething() { }
    }

    public static class GcHelper
    {
        public static void Collect()
        {
            // OK surely overkill …
Run Code Online (Sandbox Code Playgroud)

c# garbage-collection scope weak-references

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