C#中的罕见特殊符号(=>)、一些关键字的特殊用法(where)

private Func<PutPullFileServiceResult> PutPullRetry(PutPullFileServiceRequest request)
{
PutPullFileServiceResult result = new PutPullFileServiceResult();
return () => ///// 1
{
result = ServiceClient.PutPullFile(request);
return result;
};
}
上面方法位置1处,return后的 "() =>" 是上面意思,作用是什么?

public static void Retry<TException>(Action action, int sleepTime) //// 5
where TException : Exception //// 2
{
Retry<int, TException>(() => //// 3
{
action(); //// 4
return -1;
}, sleepTime);
}
上面方法2处 "where TException" 中的 "where" 是什么意思,作用是什么?
还有3处什么意思?
4处在类中并没有action();方法, 当我跳转到定义位置时就自动跑到5处action参数上,这又是什么意思?

以上问题希望各位高手指点下,先谢谢了。。。有写的不清楚的地方指出详谈啊,分数可以再加。
着急着急,。。。
第二个方法所在类的详细内容:
public static class RetryHandler
{
public static void Retry(Action action)
{
Retry<Exception>(action);
}

public static void Retry<TException>(Action action)
where TException : Exception
{
Retry<TException>(action, 0);
}

public static void Retry(Action action, int sleepTime)
{
Retry<Exception>(action, sleepTime);
}

public static void Retry<TException>(Action action, int sleepTime)
where TException : Exception
{
Retry<int, TException>(() =>
{
action();
return -1;
}, sleepTime);
}

public static TResult Retry<TResult, TException>(Func<TResult> action, int sleepTime)
where TException : Exception
{
//// 详细的业务处理。。。
}
}

where TException Retry<TException> 此参数的父类是什么. WHERE是解释语句

=> 标记称作 lambda 运算符。该标记在 lambda 表达式中用来将左侧的输入变量与右侧的 lambda 体分离。Lambda 表达式是与匿名方法类似的内联表达式,但更加灵活

=> 运算符具有与赋值运算符 (=) 相同的优先级,并且是右结合运算符。追问

=>这个符号的意思也就是说,第一个方法中return的是
result = ServiceClient.PutPullFile(request);
return result;
这个return的结果。
那他为什么=>符号前加个()啊,还是说就是这种用法?

追答

友情提示..我记得的写法是 ({})...他这个的意思其实是匿名函数啦

追问

那第二个问题能详细说下吗,where是解释语句?是什么意思,。

追答

例如 public T GetString (string a) where T:String
那么这个T只能是STRING类型的.或者说STRING或者STRING的子类
如果我写成Where T:Int
就成了INT或者INT的子类
如果是Where T:Type
这个意思是泛型了..不过写法忘记了- -手码..刚上班就看到你追问了..

温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答