今天早上正在阅读一本书,我在其中找到了如下所述的段落:
表中的每个数据字段都是强类型数据成员,完全符合.NET的Common Type System.
上述行是否意味着"用不同语言编写的对象可以相互交互"
如果它意味着以上几行,那么上述行的含义就是说不同的语言可以互相交互
我想尝试一个例子,但到目前为止没有成功.
或者是我缺少并且需要知道的东西.请帮我理解.
提前致谢
Fos*_*erZ 21
例如,你不能乘以或除以两种不同的类型,即 String vs Integer
var answer = 1 * "1"; // you cannot do this
Run Code Online (Sandbox Code Playgroud)
你必须明确地施放它,这被称为强类型
好像你在php中看到的那样
$x = "3" * 1; // is correct in php
Run Code Online (Sandbox Code Playgroud)
所以在这里你不需要明确地施展它.
Ati*_*MVP 16
当我们说强类型的东西时,我们的意思是对象的类型是已知的和可用的.
假设我有一个像下面这样的功能
public int Add(int a, int b){
return a+b;
}
Run Code Online (Sandbox Code Playgroud)
我们可以像这样调用这个函数
int result = Add(5,4);
Run Code Online (Sandbox Code Playgroud)
但我们不能这样做
int result = Add(5.2,4.5); // We will get here compilation error.
Run Code Online (Sandbox Code Playgroud)
C#(和C++和许多其他语言)是强类型的,因为编译器将在编译时检测并标记这些错误.
看到这里
归档时间: |
|
查看次数: |
39232 次 |
最近记录: |