什么是幻数42的起源,在编码中不可缺少? [英] What is the origin of magic number 42, indispensable in coding?

查看:136
本文介绍了什么是幻数42的起源,在编码中不可缺少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新:

令人惊讶的是,它被严重落败...

Update:
Surprised that it is being so heavily downvoted...

问题是与编码相关,在提出此问题之前,我已结合使用42结合使用:

The question is coding-related and before asking this question I have googled for "42" in combination with:


  • :msdn.micrsoft.com

  • code example

  • c#

  • 幻数

  • site:msdn.micrsoft.com
  • "code example"
  • "c#"
  • "magic number"

我不是西方文化/文学的专家/

And I am not an expert/fan of Western culture/literature.

也找到了为什么变量i和j用于计数器? [duplicate] 没有关闭,甚至受到保护。

Also found, Why are variables "i" and "j" used for counters? [duplicate] which was not closed but even protected.

我觉得大家都知道,除了我...

I feel that everybody knows it, except me...

在遍布代码样本和样本中使用的泛指魔术数字42的起源是什么?

What is the origin of ubiquitous magic digit 42 used all over the code samples and samples?

你如何使用42?因为我从来没有使用过 42

How have you come using 42? because I have not ever come or ever used 42

经过一番搜索,我发现了MSDN文档:麻将数字:整数

After some search, I found MSDN doc on it: Magic Numbers: Integers:


  • 除了书/电影参考之外,开发人员通常将此作为任意值使用

  • "Aside from a book/movie reference, developers often use this as an arbitrary value"

这没有解释我什么。

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

Which movies and books have I missed for all those years of being involved in development, coding and programming and around-IT related activities like rwquirements analysis, system administration, etc??

JérômeLaban。 C#异步提示和技巧,第3部分:任务和同步上下文

Jérôme Laban. C# Async Tips and Tricks, Part 3: Tasks and the Synchronization Context

  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);

a href =http://msdn.microsoft.com/en-us/magazine/hh781020.aspx>使用PPL的C ++中的异步编程

Asynchronous Programming in C++ Using PPL

  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(编程语言)

WIKIPedia C Sharp (programming language)

  int foo = 42;         // Value type.


推荐答案

答案是,正如人们已经说过的, Hitchhiker's

The answer is, as people already have stated, The Hitchhiker's Guide to the Galaxy.

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

I made a little experiment and put a couple of numbers in the search field, and these are the results:

看起来像是清楚地击败了它的邻居,但它不能接触正常的数字,如40,45和50,无论它是多么神奇。

It seems like 42 beats its neighbors clearly, but it can't touch regular numbers like 40, 45 and 50, no matter how magical it is.

只需在源代码中执行相同的搜索即可。

It would be interesting to do the same search in source code only.

这篇关于什么是幻数42的起源,在编码中不可缺少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆