小编Kyl*_*yle的帖子

来自Ruby Wilson的C#得分

任何人都可以帮助我将其转换为C#.这实际上伤害了我的大脑.

http://www.evanmiller.org/how-not-to-sort-by-average-rating.html

威尔逊得分

require 'statistics2'

def ci_lower_bound(pos, n, power)
    if n == 0
        return 0
    end
    z = Statistics2.pnormaldist(1-power/2)
    phat = 1.0*pos/n
    (phat + z*z/(2*n) - z * Math.sqrt((phat*(1-phat)+z*z/(4*n))/n))/(1+z*z/n)
end
Run Code Online (Sandbox Code Playgroud)

这是什么意思?

Statistics2.pnormaldist(1-power/2) 
Run Code Online (Sandbox Code Playgroud)

c# ruby

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

C#将Lambda表达式函数转换为描述性字符串

我有一个非常不必要的困境.我懒洋洋地寻找一个将lamda表达式转换为字符串的函数.我每次都在输入这个缓存密钥让我感到困扰,但我真的不想花时间去创建它.

我想用它来创建我创建的缓存函数:

如果我想在没有每次调用函数的情况下为某个人获取名称的话.

public static string GetPersonName(int id)
{
    return Repository.PersonProvider.Cached(x => x.GetById(id)).Name;
}
Run Code Online (Sandbox Code Playgroud)

GetExpressionDescription将返回"PersonProvider.GetById(int 10)"

我认为这是可能的,但我想知道是否有人已经建立了这个或已经在某处看到它.

public static R Cached<T, R>(this T obj, Expression<Func<T, R>> function, double hours = 24)
{
    var expressionDescription = GetExpressionDescription(function); 
    return Cached(function, expressionDescription, hours); 
}

public static R Cached<T, R>(this T obj, Expression<Func<T, R>> function, string cacheName, double hours = 24)
{
    var context = HttpContext.Current;
    if (context == null)
        return function.Compile().Invoke(obj);

    R results = default(R);
    try { results = (R)context.Cache[cacheName]; }
    catch { …
Run Code Online (Sandbox Code Playgroud)

c# lambda

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

获取null对象的基础类型

User x = null;
object o = x;
// determine type with only reference to o
Run Code Online (Sandbox Code Playgroud)

并且泛型不起作用

c#

-2
推荐指数
2
解决办法
2913
查看次数

标签 统计

c# ×3

lambda ×1

ruby ×1