26

更新:
很惊讶它被如此严重地否决......

这个问题与编码有关,在问这个问题之前,我已经搜索了“42”并结合:

  • 站点:msdn.micrsoft.com
  • “代码示例”
  • “C#”
  • “神奇数字”

而且我不是西方文化/文学的专家/粉丝。

还发现,为什么变量“i”和“j”用于计数器?[重复]没有关闭但甚至受到保护。


我觉得每个人都知道,除了我...

在整个代码示例和示例中使用的无处不在的魔术数字 42 的起源是什么?

你是怎么用42的?因为我从来没有来过,也没有用过42

经过一番搜索,我找到了 MSDN 文档: Magic Numbers: Integers

  • “除了书籍/电影参考之外,开发人员经常将其用作任意值”

好吧,这并没有解释什么。

在参与开发、编码和编程以及与 IT 相关的活动(如 rwquirements 分析、系统管理等)的这些年里,我错过了哪些电影和书籍?

使用带有 42 的代码片段(仅与 C# 相关)对某些文本的一些引用:

杰罗姆·拉班。C# 异步提示和技巧,第 3 部分:任务和同步上下文

  var t = Task.Delay(TimeSpan.FromSeconds(1))
              .ContinueWith
                (
                    _ => Task.Delay(TimeSpan.FromSeconds(42))
                );

MSDN异步代理库

   send(_target, 42);  

快速入门:在 C# 或 Visual Basic 中调用异步 API

  Office.context.document.setSelectedDataAsync(
      "<html><body>hello world</body></html>",
       {coercionType: "html", asyncContext: 42},
       function(asyncResult) {
           write(asyncResult.status + " " + asyncResult.asyncContext);

使用 PPL 在 C++ 中进行异步编程

  task<int> myTask = someOtherTask.then([]() { return 42; });

装箱和拆箱(C# 编程指南)

  Console.WriteLine(String.Concat("Answer", 42, true));

如何:覆盖 ToString 方法(C# 编程指南)

  int x = 42;

跟踪侦听器

  // Use this example when debugging.
  System.Diagnostics.Debug.WriteLine("Error in Widget 42");
  // Use this example when tracing.
  System.Diagnostics.Trace.WriteLine("Error in Widget 42");

|| 运算符(C# 参考

  // The following line displays True, because 42 is evenly  
  // divisible by 7.
  Console.WriteLine("Divisible returns {0}.", Divisible(42, 7));

  // The following line displays False, because 42 is not evenly 
  // divisible by 5.
  Console.WriteLine("Divisible returns {0}.", Divisible(42, 5));

  // The following line displays False when method Divisible  
  // uses ||, because you cannot divide by 0. 
  // If method Divisible uses | instead of ||, this line 
  // causes an exception.
  Console.WriteLine("Divisible returns {0}.", Divisible(42, 0));

WIKIPedia C Sharp(编程语言)

  int foo = 42;         // Value type.
4

6 回答 6

28

出自《银河系搭便车者指南》

在《银河系漫游指南》(1979 年出版)中,角色们造访了传说中的玛格拉西亚星球,这里是现在已经倒闭的行星建造业的所在地,并会见了负责挪威峡湾的行星海岸线设计师 Slartibartfast。通过档案记录,他讲述了一个超智能泛维度生物种族的故事,他们建造了一台名为 Deep Thought 的计算机来计算生命、宇宙和一切终极问题的答案。当答案显示为 42 时,Deep Thought 解释说答案是不可理解的,因为众生不知道他们在问什么。它继续预测另一台比它自己更强大的计算机将由它制造和设计来计算答案的问题。(后来,参考这个,

于 2013-04-26T12:15:46.607 回答
16

正如人们已经说过的那样,答案是《银河系漫游指南》

我做了一个小实验,在搜索字段中输入了几个数字,结果如下:

在此处输入图像描述

看起来 42 显然击败了它的邻居,但它无法触及像 40、45 和 50 这样的常规数字,无论它多么神奇。

仅在源代码中进行相同的搜索会很有趣。

于 2013-04-26T12:28:37.123 回答
9

老兄!

它是生命、宇宙和一切终极问题的答案!由 Deep Thought 超级计算机计算,耗时 750 万年!

http://en.wikipedia.org/wiki/The_answer_to_life_the_universe_and_everything#Answer_to_the_Ultimate_Question_of_Life.2C_the_Universe_and_Everything_.2842.29

于 2013-04-26T12:17:22.023 回答
7

看看这个。42 是ultimate answer to the ultimate question of life the universe and everything

于 2013-04-26T12:17:21.470 回答
4

这是来自银河系的搭便车徒步旅行者指南,是:

生命、宇宙和一切终极问题的答案

维基链接

于 2013-04-26T12:16:26.163 回答
4

请参阅The Hitch Hiker's Guide to Galaxy。

于 2013-04-26T12:16:58.037 回答