Re: [问题] 新手学C#,有关{get;set;}的疑问

楼主: AmosYang (泛用人型编码器)   2015-01-01 06:05:26
※ 引述《StupidGaGa (笨嘎嘎)》之铭言:
: 个人对于用不用TimeZoneInfo没什么想法,
: 但是“时区转换”用TimeZoneInfo就比较高尚吗?
: 单纯的用加减时数就比较老旧吗?
与其去争论“老旧”或“高尚”,不如看看现实
* Time Zone Database
http://www.iana.org/time-zones
The Time Zone Database (often called tz or zoneinfo) contains
code and data that represent the history of local time for many
representative locations around the globe. It is updated periodically
to reflect changes made by political bodies to time zone boundaries,
UTC offsets, and daylight-saving rules.
* TimeZoneInfo.cs
http://referencesource.microsoft.com/#mscorlib/system/timezoneinfo.cs
其中所需要考量到的各种大小细节, 事实上远超乎一般人的想像
* 与“时间”有关的经典案例
http://stackoverflow.com/questions/6841333/why-is-subtracting-these-two-times-in-1927-giving-a-strange-result
相关讨论: https://news.ycombinator.com/item?id=6661392
除非是不需要处理日期、历法、时制、时区这类给“人”看的时间,
,不然,直接对时间作运算处理是极困难复杂的题目;宁可小心些,
也不该让新手有误解的可能性
: 如同有人问说如何在textBox换行,
: 某人回答 \r\n,后来有人很回说用 Environment.NewLine,
: 然后还说 \r\n 别土法炼钢,建议用 Environment.NewLine比较好,
: 我很想问,有差吗?
一个是 constant, 一个是 property ... "Effective C#" 里也讨论
过类似话题,网络上也有相关讨论
* http://stackoverflow.com/questions/9286645/constant-value-properties
* http://stackoverflow.com/questions/55984/what-is-the-difference-between-const-and-readonly
* http://blog.codinghorror.com/properties-vs-public-variables/
* http://programmers.stackexchange.com/questions/132747/is-having-public-constants-bad
讨论深入点的话,就 constant/field vs. property 的影响来说,
从 compile time .NET assembly layout 到 runtime CPU cache hit/miss
都是可以谈的; 更不用说,对程式本身的可移植性(portability) 的
影响。
: 我只想说,
: 不能因为微软都帮你处理好了就笨笨的去用那些封装method,
: 结果变成只会用,但不知道为何的程式设计师,
: 有时候土法炼钢也是能学到不少东西。
“追根究底”与“土法炼钢”是不同的;在你举的例子里,若对 Environment.NewLine
的实作有疑惑,可以选择用 ildasm.exe 把 mscorlib.dll 打开来看
,或可看其原始码 ( http://referencesource.microsoft.com/ )
public static String NewLine {
get {
Contract.Ensures(Contract.Result<String>() != null);
#if !PLATFORM_UNIX
return "\r\n";
#else
return "\n";
#endif // !PLATFORM_UNIX
}
}
都是更为积极、正面的研究办法
: 如果觉得这举例不好,那过几天后我看看情况自删文章,
: 反正贴code还会被认为误导,以后打嘴砲就好,
: 反正用说的比用实作举例简单多了。
http://en.wikipedia.org/wiki/Hasty_generalization
作者: YahooTaiwan (超可爱南西我老婆)   2015-01-01 15:40:00
推给微软 这个观点我喜欢 XDD
作者: GoalBased (Artificail Intelligence)   2015-01-01 17:56:00
原来还有这种八卦XD
作者: fireslayer (fireslayer)   2015-01-01 22:57:00
现在蛮多linux dist的安装也是用点的说虽然opensource可能比较不怕政治压力就是..
作者: uranusjr (←這人是超級笨蛋)   2015-01-02 00:45:00
别说 Linux 了, OS X 也是用点的啊...
作者: andymai (人生只有一次)   2015-01-02 09:00:00
也不算是树大招风吧?要开发作业系统~这也是不得不考虑进去的事啊~尤其是他又不可能只吃一个国家的市场...
作者: james732 (好人超)   2015-01-04 14:56:00
国家、时区用拉的超麻烦啊.....

Links booklink

Contact Us: admin [ a t ] ucptt.com