什么是"天然的QUOT;和"字面"关键字 [英] What are "native" and "literal" keywords

查看:346
本文介绍了什么是"天然的QUOT;和"字面"关键字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C#中使用的文章本地文本关键词看到许多倍。他们是什么意思



例子:



的String.Empty 文章




的空常量持有空字符串值。我们需要调用
String构造这样编译器不将此标记为
文字。此标记作为文字将意味着它不会出现
作为我们可以从本地


访问一个字段

C#和Java维基百科的文章:




简单/原始类型的结果
两种语言都支持一些内置的将被复制
型和价值,而不是按引用传递。
Java调用这些类型的原始类型,而他们被称为C#中简单的
类型。简单/原始类型通常的本地支持
从底层的处理器架构。



解决方案

从C#规范第2.4.4节:




A 文字是,一个值的源代码表示。




因此,例如,有字符串和数字文字:

 字符串x =你好; 
INT Y = 10;



...但C#有日期和时间没有文字语法;你必须使用:

  DateTime的DT =新日期时间(2011,12,11); 



至于原生支持 - 存在着不同程度的原生在这里,但就C#是关注,我通常认为这类型相关的以任何输出格式使用的支持。因此,例如,有的IL指令来处理二进制浮点类型(浮动双击),但是当C#编译器生成代码处理小数值,它必须调用 System.Decimal 。因此,我认为浮动双击拥有的原始的IL中的支持,但小数没有。​​



(这将有可能写一个C#编译器针对不同的平台,它的没有的有小数原生支持 - 或没有为浮动和<$原生支持C $ C>双击,例如,不可能的,但可能的。)



然后,当IL是在执行引擎中运行,这86例如 - - 将上真正的原生代码之上运行,可以对某些特定类型的支持。这就是本地另一个层次。例如,如果有人想出了IL的新版本,其中包括用于 小数,那并不意味着他们的CPU突然获得了原生支持原生支持。


I see many times using native and literals "keywords" in C# articles. What do they mean?

examples:

string.Empty article:

The Empty constant holds the empty string value. We need to call the String constructor so that the compiler doesn't mark this as a literal. Marking this as a literal would mean that it doesn't show up as a field which we can access from native.

C# vs Java Wikipedia article:

Simple/primitive types
Both languages support a number of built-in types which are copied and passed by value rather than by reference. Java calls these types primitive types, while they are called simple types in C#. The simple/primitive types typically have native support from the underlying processor architecture.

解决方案

From the C# spec section 2.4.4:

A literal is a source code representation of a value.

So for example there are literals for strings and numbers:

string x = "hello";
int y = 10;

... but C# has no literal syntax for dates and times; you'd have to use:

DateTime dt = new DateTime(2011, 12, 11);

As for native support - there are different levels of "native" here, but as far as C# is concerned, I'd usually consider it type-specific support in whatever output format is used. So for example, there are IL instructions to deal with the binary floating point types (float, double) but when the C# compiler emits code dealing with decimal values, it has to call the operators declared in System.Decimal. I'd therefore consider that float and double have native support in IL, but decimal doesn't.

(It would be possible to write a C# compiler targeting a different platform which did have native support for decimal - or which didn't have native support for float and double, for example. Unlikely, but possible.)

Then when the IL is being run in an execution engine, that will be running on top of "real" native code - x86 for example - which can have specific support for certain types. That's another level of "native". For example, if someone came up with a new version of IL which included native support for decimal, that wouldn't mean that the CPUs themselves suddenly gained native support.

这篇关于什么是&QUOT;天然的QUOT;和&QUOT;字面&QUOT;关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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