一段C#代码
var isTrue = (new List<int>{1,2,3} is IEnumerable<object>);
Run Code Online (Sandbox Code Playgroud)
我得到false
了代码执行的结果,但是当我将该代码复制到WATCH窗口时,结果是true
.
目前我有两种方式:
当我设置我的web.config cookieless="UseCookies"
我的网址看起来:
<sessionState timeout="60" cookieless="UseCookies"/>
当我设置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)
这必须是SessionStart
Global.asax中的某个地方
为什么我的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)