c#的implicit operator是一个定义隐式类型转换的接口,不过c#不允许interface参与其中,也即,以下代码是被拒绝的:
class A<T>
{
public static implicit operator A<T>(IEnumerable<T> e)
{ return null; }
}
编译器道:
user-defined conversions to or from an interface are not allowed
老爷以为interface的隐转是有必要的,叵耐c#编译器必要来相阻,正没作理会处,看见园友 装配脑袋 的一篇博文的回复中有提到SpecialName attribute,且去一试
果然绕过了c#:
public class A<T>
{
[SpecialName]
public static A<T> op_Implicit(IEnumerable<T> e)
{ return null; }
}
然后即可:
A<Char> a="abc";
只是波浪线看着心乱-_-!
posted @ 2011-09-18 09:48 Lumj 阅读(870) 评论(4) 编辑
javascript Date
0.getDate/setDate的从1数起,而getDay/setDay等等却从0数起,嫌世界不够混乱还是怎的?
1.new Date()直接得到当前时间,自作聪明
2.名为Date,却有个getDate用来得到月中的天序号,制造神秘感
3.名为Date,其实却包含了精确到ms的时间,深藏不露,好了不起么?
4.
setHours的原型是setHours(hour,minute,second,millisecond);
setMinutes的原型是setMinutes(minute,second,millisecond);
我不太能相信眼前所看到的
之外,Date的计算是这样的:傻傻地get,算好,傻傻地set回去,minute超出59怎么办?它会告诉你:不要紧,超出的部分会进位
唉..第一篇'随笔'就如此阴郁
posted @ 2011-04-30 21:53 Lumj 阅读(47) 评论(0) 编辑