什么是一个int和Java和C#的整数之间的区别? [英] What is the difference between an int and an Integer in Java and C#?

查看:176
本文介绍了什么是一个int和Java和C#的整数之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是坐在我的地方国界的喝着咖啡,看的More乔尔的软件 的(免费),当我遇到的乔尔斯波斯基说一些关于知道一个int和使用Java / C#(面向对象编程语言的整数)之间的区别特定类型的程序员。

I was just sitting at my local Borders sipping coffee and reading More Joel on Software (for free) when I came across Joel Spolsky saying something about a particular type of programmer knowing the difference between an int and an Integer in Java/C# (Object Oriented Programming Languages).

一个快速后的大脑检查,我意识到,我沮丧的是,我不知道答案。

After a quick 'brain check,' I realized, to my dismay, that I didn't know the answer.

推荐答案

在Java中,的'廉政'类型是基本,而整数类型的对象。

In Java, the 'int' type is a primitive , whereas the 'Integer' type is an object.

在C#中,的'廉政'类型是一样的 System.Int32 是的值类型(即更像是java的'廉政')。一个整数(就像任何其他值类型)可以盒装(包装)成目的。

In C#, the 'int' type is the same as System.Int32 and is a value type (ie more like the java 'int'). An integer (just like any other value types) can be boxed ("wrapped") into an object.

对象和原语之间的差别是有些超出了这个问题的范围,但总结:

The differences between objects and primitives are somewhat beyond the scope of this question, but to summarize:

对象作为多态性提供的设施,按引用传递(或更精确地有值传递的引用),并从的。相反,是由值传递的,而且往往从

Objects provide facilities for polymorphism, are passed by reference (or more accurately have references passed by value), and are allocated from the heap. Conversely, primitives are immutable types that are passed by value and are often allocated from the stack.

这篇关于什么是一个int和Java和C#的整数之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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